Uh oh!
There was an error while loading. Please reload this page.
fix: strip inline env var prefixes from bash permission patterns - #28475
fix: strip inline env var prefixes from bash permission patterns#28475prullanferragut wants to merge 1 commit into
Conversation
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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
864269b to
ce5a3fdCompareAutomated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
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