fix(tool/read): match permission patterns against worktree-relative path#26583
Merged
Conversation
The read tool checked permissions with the absolute filepath while
edit/write/apply_patch all check against `path.relative(instance.worktree,
filepath)`. So a user rule like `"read": { "src/*": "deny" }` matched the
worktree-relative path under edit and worked, but matched against the
absolute path under read and silently fell through to `"*": "allow"` —
same rule, same file, different outcome.
Use the worktree-relative form everywhere. Closes #26524.
This was referenced May 10, 2026
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.
Closes #26524.
Problem
readchecked permissions with the absolute filepath.edit,write, andapply_patchall check againstpath.relative(instance.worktree, filepath). So a user rule like:```json
{
"permission": {
"read": { "": "allow", "src/": "deny" },
"edit": { "": "allow", "src/": "deny" }
}
}
```
denied edits to `src/foo.ts` (correct — the relative `src/foo.ts` matched `src/`), but allowed reads (the absolute `/abs/.../src/foo.ts` did not match `src/` and fell through to `*`). Same rule, same file, different outcome.
Fix
`packages/opencode/src/tool/read.ts:181` — use `path.relative(instance.worktree, filepath)` like the other tools.
Verification