fix(opencode): evaluate apply_patch move destination in edit permission ruleset - #29
Open
detail-app[bot] wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
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.
Detail bug report: View on Detail
Issue for this PR
Closes #
Type of change
What does this PR do?
apply_patchmove hunks bypassed destination-scopededitpermission rules. Thepatternsarray passed toctx.askwas built from only the source path (c.filePath), never the move destination (c.movePath). So a configured rule like{ "permission": { "edit": { "secret/*": "deny" } } }was silently ignored for moves intosecret/, while directedit/writecalls to the same path were correctly blocked. In--automode (auto-approve anything not explicitly denied), this became a silent bypass of the operator's deny rule.Root cause:
apply_patch.tsbuiltrelativePathswithfileChanges.map((c) => path.relative(worktree, c.filePath))— source only.Permission.askonly evaluates rules for patterns inrequest.patterns, so the destination never reached the ruleset. This is asymmetric withedit.ts/write.ts, which pass the write target inpatterns.Fix: Build
relativePathswithflatMap, appending both the source and destination relative paths whenever a change has amovePath. The destination now reaches theeditruleset just like the write target inedit/write. Out-of-worktree destinations keep their existingexternal_directorygate unchanged.How did you verify your code works?
apply_patch.test.ts:move includes destination in permission patterns— asserts both source and destination appear inctx.askpatterns.destination-scoped edit deny blocks a move (auto mode)— uses a realPermission.fromConfigruleset driven through amakePermissionCtxmock mirroring--automode; asserts the move fails,secret/notes.txtis never created, and the source is intact.move into non-denied destination still succeeds through the ruleset— samesecret/*: denyruleset but moving intoallowed/; asserts the move succeeds, proving the deny doesn't over-block.opencode run --dangerously-skip-permissionsCLI binary against an in-process test LLM server with agpt-5model +secret/*: denyconfig: without the fixsecret/notes.txtwas created (deny bypassed); with the fix the move was blocked. Repeated through an ACP subprocess with an auto-approvingrequestPermissionhandler with the same result.tsgo --noEmit), and lint (oxlint) all pass with 0 errors.Checklist
Automatic Fixes PRs can be configured here.