permissions: match absolute rules for paths outside the project root - #175
Draft
iceteaSA wants to merge 1 commit into
Draft
permissions: match absolute rules for paths outside the project root#175iceteaSA wants to merge 1 commit into
iceteaSA wants to merge 1 commit into
Conversation
Author
|
Cross-reference: opencode core has the same bidirectional bug in its own permission matching, fixed upstream in anomalyco/opencode#40149 (their exhibit: That fix only covers opencode-native tools. Since AFT hoists |
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.
Permission patterns for edit/write are always relativized against the project root, so any rule written as an absolute path outside that root can never match.
With this config:
a write to
/tmp/report.mdproduces the pattern../../../../tmp/report.md./tmp/**doesn't match it,"*": "deny"wins, and the write is denied.It fails in the dangerous direction too. Reverse the rules:
The deny rule is equally unmatchable, so the write is allowed. An absolute deny rule written to protect a path silently protects nothing.
Since AFT hoists
write/edit/apply_patch, this is the layer that decides — opencode's own permission handling isn't reached for those tools.Change
New
permissionPathhelper intools/permissions.ts:/→ absoluteresolveRelativePattern,resolveRelativePatternFromAbsolute, andresolveRelativePatternsnow delegate to it, soimports.ts,refactoring.ts,safety.ts, andast.tsinherit the fix without changes. The two inlinepath.relativesites inhoisted.ts(write, edit) call it directly.apply_patchneeded more than the shared helper: its patterns come from the Rust side, wherebuild_preview_responseemitsaffected_rel_pathsalongsideaffected_paths. The TS side was reading the relative array. It now prefers the absolute one and falls back to the relative when it's empty, normalizing both throughpermissionPath.Note on the helper names
resolveRelativePatternandresolveRelativePatternFromAbsolutecan now return absolute paths, so the names are stale. Left alone here to keep the diff focused — happy to rename in this PR or a follow-up, whichever you prefer.Tests
permissions-effect.test.tsdrives the real tool path (hoistedTools(ctx).write.execute(...)), not the helper in isolation, and covers write and apply_patch separately. RevertingpermissionPathto the old one-liner fails them withExpected: "/tmp/x"/Received: "../../tmp/x".18 pass in that file; 12 pass across
registration-parityandtool-surface-transport-invariant;bun run buildclean. Full plugin suite matches baseline (2 pre-existingformat_on_editfailures, both environmental — formatters installed locally where those tests expect absence).Preview and execution still receive identical raw args — the pattern only reaches the host permission ask, never the Rust side, so plugin and server can't disagree about the path.
Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.Summary by cubic
Fix permission pattern handling so absolute rules outside the project root match correctly for
write,edit, andapply_patch, preventing unsafe allows and unintended denies.permissionPathto return relative paths for in-project targets and absolute paths for outside-root or/worktrees.write,edit, andapply_patchto usepermissionPath;apply_patchnow prefersaffected_pathsand falls back toaffected_rel_paths, then normalizes./tmp/**will match/tmp/x).permissionPath.Written for commit 3d2b566. Summary will update on new commits.