fix(security): sanitize gstack-slug output against shell injection#138
Open
elliotllliu wants to merge 1 commit intogarrytan:mainfrom
Open
fix(security): sanitize gstack-slug output against shell injection#138elliotllliu wants to merge 1 commit intogarrytan:mainfrom
elliotllliu wants to merge 1 commit intogarrytan:mainfrom
Conversation
The eval $(gstack-slug) pattern used across 14+ skill templates passes git-derived values (remote URL, branch name) through eval without stripping shell metacharacters like ;, $(), backticks, |. Add a sanitize function that strips everything except [a-zA-Z0-9._-] from both SLUG and BRANCH before output. This hardens all existing callers without requiring changes to any template file. Risk was low (GitHub/GitLab enforce safe naming) but defense-in-depth matters for self-hosted git servers or exotic remote URLs. Fixes garrytan#133
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #133 — hardens
bin/gstack-slugagainst shell injection when consumed viaeval $(gstack-slug).Problem
gstack-slugderives SLUG and BRANCH fromgit remote get-url originandgit rev-parse --abbrev-ref HEAD. The existing pipeline (sed+tr '/' '-') does not strip shell metacharacters like;,$(), backticks, or|. Since the output is consumed viaevalin 14+ skill templates, a malicious remote URL or branch name could execute arbitrary commands.Fix
Added a
sanitize()function that strips everything except[a-zA-Z0-9._-]viatr -cd. Applied to both SLUG and BRANCH before output. All existingeval $(gstack-slug)callers are automatically protected without template changes.Risk context
Low severity — GitHub and GitLab enforce alphanumeric naming for orgs/repos/branches, so hosted repos are safe. This is defense-in-depth for self-hosted git servers or exotic remote URLs.