Repository navigation
fix(opencode): check permission for bare redirects with no parsed command - #53597
Closed
DSHCorrectover wants to merge 1 commit into
Closed
DSHCorrectover wants to merge 1 commit into
DSHCorrectover wants to merge 1 commit into
Conversation
DSHCorrectover
force-pushed
the
fix/bare-redirect-permission
branch
from
October 6, 2026 20:15
c13030b to
e6d8399
Compare
Author
|
Note for maintainers: the |
DSHCorrectover
force-pushed
the
fix/bare-redirect-permission
branch
from
October 6, 2026 20:18
178c3cd to
e6d8399
Compare
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
Member
|
This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2. — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊 |
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 #49948
Type of change
What does this PR do?
A bare redirect like
> fileor>> fileis valid POSIX — it truncates or creates the target file — but the tree-sitter shell scanner parses it into zerocommandnodes. The shell tool built its permission patterns only from parsed commands, so a zero-command statement produced no patterns and the permission check was skipped entirely. The statement then ran unchecked even with an explicit deny:The issue predates the current scanner, but this still reproduces on
dev: both> victim.txtand>> victim.txtparse to 0commandnodes, so nothing is asserted before they execute.The fix: while scanning, also look at
redirected_statementnodes. A redirected statement with no command body (the bare-redirect case) is added as a permission pattern using its raw text, so it flows through the same evaluation as any other statement — denied by an explicit deny, allowed by an explicit allow, or shown as a prompt otherwise. Redirects that do have a command (e.g.echo hi > out.txt) keep their existing pattern and are unaffected.Scope note
The issue also points to a second fail-open in
packages/core/src/permission.ts: an empty resource list falls through toallow. That file belongs to the separate legacy permission system, and changing its default could affect behavior well beyond this path, so I did not touch it here. With this change the shell path no longer reaches that state for bare redirects because a pattern is always produced.How did you verify your code works?
Added three regression tests in
packages/opencode/test/tool/shell.test.ts:> victim.txtis denied under a wildcard deny rule and the file is not truncated.>> victim.txtproduces onebashpermission prompt whose pattern is the raw statement.echo hi > out.txtkeeps its single existing pattern (no extra bare-redirect pattern, no duplicate prompt).Results on a clean tree:
bun test test/tool/shell.test.ts— 26 pass / 0 failbun test test/permission/next.test.ts test/permission-task.test.ts— 100 pass / 0 failtsgo --noEmit— passesoxlinton the two changed files — 0 errors (12 pre-existing warnings)Screenshots / recordings
N/A — no UI change.
Checklist