Skip to content

fix: harden gstack-slug against shell injection via eval#181

Open
Ty-Robb wants to merge 1 commit intogarrytan:mainfrom
Ty-Robb:fix/shell-injection-gstack-slug
Open

fix: harden gstack-slug against shell injection via eval#181
Ty-Robb wants to merge 1 commit intogarrytan:mainfrom
Ty-Robb:fix/shell-injection-gstack-slug

Conversation

@Ty-Robb
Copy link

@Ty-Robb Ty-Robb commented Mar 18, 2026

Summary

Addresses #133

Hardens bin/gstack-slug against shell injection when used with eval $(gstack-slug). Appends | tr -cd 'a-zA-Z0-9._-' to the SLUG and BRANCH pipelines, whitelisting only safe characters in the output. Shell metacharacters (;, $, backticks, |, &, etc.) are stripped before they reach eval.

Changes

  • bin/gstack-slug — Added character whitelist to both pipelines (+2 lines, inline with existing tr calls)
  • test/skill-validation.test.ts — Added assertion that output values contain only safe characters

Risk

None. Output is unchanged for standard GitHub/GitLab repos — org names, repo names, and branch names already use only safe characters. Only affects edge cases with self-hosted git servers or crafted branch names.

gstack-diff-scope uses the same eval $(...) pattern but is not affected — it only outputs true/false literals.

Test plan

  • All 212 validation tests pass (was 211, +1 new)
  • Manually verified output: SLUG=Ty-Robb-gstack BRANCH=fix-shell-injection-gstack-slug

Pre-Landing Review

No issues found — change is 2 lines of pipeline hardening + 9 lines of test.

Whitelist safe characters (a-zA-Z0-9._-) in SLUG and BRANCH output
to prevent shell metacharacter injection when used with eval.

Only affects self-hosted git servers with lax naming rules — GitHub
and GitLab enforce safe characters already. Defense-in-depth.
@Ty-Robb Ty-Robb force-pushed the fix/shell-injection-gstack-slug branch from a1cc067 to 02c76d3 Compare March 18, 2026 09:18
@Ty-Robb Ty-Robb changed the title fix: harden gstack-slug against shell injection via eval (#133) fix: harden gstack-slug against shell injection via eval Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant