fix: strip inline env var prefixes from bash permission patterns#28475
Draft
prullanferragut wants to merge 1 commit into
Draft
fix: strip inline env var prefixes from bash permission patterns#28475prullanferragut wants to merge 1 commit into
prullanferragut wants to merge 1 commit into
Conversation
Commands like 'GITHUB_TOKEN=x git push --force' were matching '*': allow instead of the intended deny rule because variable_assignment nodes were included in the pattern string used for permission matching. Build the permission pattern from parts() tokens (which already exclude variable_assignment children) rather than from the raw node text, then re-attach any redirection suffix from the parent redirected_statement so 'echo test > output.txt' still produces the full pattern as before. Also adds integration tests verifying the corrected behavior. Based on test groundwork from PR anomalyco#16086. Fixes issue anomalyco#16075
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #16075
Type of change
What does this PR do?
In
collect()insideshell.ts, the permission pattern for a command was built by callingsource(node), which returns the rawnode.text. For a command likeGITHUB_TOKEN=x git push --force, tree-sitter parses thevariable_assignmentas a child of thecommandnode, sonode.textincludes it. The resulting patternGITHUB_TOKEN=x git push --forcedoes not match a rule like"git push --force*": deny, allowing the bypass.The
parts()function already walks the command node's children and intentionally skipsvariable_assignmentnodes — it's what builds thetokensarray used for thealwayspattern, which was already correct. The fix replacessource(node)withtokens.join(" ")for thepatternsentry, bringing it in line with howalwayswas already computed. Redirection suffixes (e.g.> output.txt,2>&1) are re-attached from the parentredirected_statementnode so that existing redirect-pattern matching continues to work.The now-dead
source()function is removed.How did you verify your code works?
Ran
bun test test/tool/shell.test.ts --timeout 60000— 26 pass, 0 fail.Three new integration tests exercise the permission-scanning path directly via the
capture()helper (halting execution at the permission prompt):CI=true git commit -m "test"→ pattern must begit commit -m "test", not containCI=trueFOO=1 BAR=2 echo hello→ pattern must beecho hello, not containFOO=1CI=true echo hello > output.txt→ pattern must beecho hello > output.txt, not containCI=true(exercises both branches simultaneously)The existing redirect test (
echo test > output.txt→echo test > output.txt) continues to pass, confirming the redirection re-attachment is correct.Test groundwork from #16086.
Screenshots / recordings
N/A — no UI change.
Checklist