Skip to content

fix(tool/read): match permission patterns against worktree-relative path#26583

Merged
kitlangton merged 1 commit into
devfrom
worktree-read-permission-relative-path
May 9, 2026
Merged

fix(tool/read): match permission patterns against worktree-relative path#26583
kitlangton merged 1 commit into
devfrom
worktree-read-permission-relative-path

Conversation

@kitlangton
Copy link
Copy Markdown
Contributor

Closes #26524.

Problem

read checked permissions with the absolute filepath. edit, write, and apply_patch all check against path.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

  • Updated `test/tool/read.test.ts` Windows assertion to expect the relative form (was the only test hard-coded to absolute).
  • Added a regression test that asserts `read` patterns are worktree-relative so a `src/*` rule would match.
  • 38/38 tests in `test/tool/read.test.ts` pass.

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.
@kitlangton kitlangton merged commit ba9e4b6 into dev May 9, 2026
12 checks passed
@kitlangton kitlangton deleted the worktree-read-permission-relative-path branch May 9, 2026 22:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read permission patterns are evaluated as absolute paths, not worktree-relative like edit/write/apply_patch

1 participant