Skip to content

fix(core): match absolute permission rules for relative paths - #53365

Closed
Shalin-Shah-2002 wants to merge 1 commit into
anomalyco:devfrom
Shalin-Shah-2002:fix-plan-dir-permission
Closed

Shalin-Shah-2002 wants to merge 1 commit into
anomalyco:devfrom
Shalin-Shah-2002:fix-plan-dir-permission

Conversation

@Shalin-Shah-2002

@Shalin-Shah-2002 Shalin-Shah-2002 commented Oct 5, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #50241
Closes #46358

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The Plan agent can't write to ~/.opencode/plan/ when that directory is inside the project. File tools pass paths inside the project as relative resources (.opencode/plan/work.md), but the Plan agent's allow rule is absolute (<home>/.opencode/plan/*). The absolute rule never matches, so the earlier edit * deny wins.

Fix is in packages/core/src/permission.ts: for read/edit, absolute rules are also matched against the resolved absolute path. Relative rules and last-match-wins order are unchanged, and Permission.evaluate keeps its signature. This is the same approach as the earlier PR #46495, which was closed by the cleanup bot without review.

I did not change the Plan guard message in plugin/plan.ts; it still rewrites any blocked edit to "outside the Plan directory".

How did you verify your code works?

  • New unit tests in test/permission.test.ts fail without the fix.
  • New test/plan-write.test.ts uses the real Plan rules, Permission, FileAccess and write tool: writes to the Plan dir succeed (relative/absolute, inside/outside the project); other paths, plan-evil and .. traversals stay blocked.
  • Permission, plan, file-access and read/edit/write/patch suites pass; typecheck, prettier and oxlint are clean.
  • The full core suite has unrelated shell/GitLab/session-shell failures that also fail on clean origin/v2.

Screenshots / recordings

N/A, not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

🤖 Generated with Claude Code

File tools pass Location-relative resources for paths inside the project, so
absolute read/edit rules (such as the Plan agent's allow for the Plan
directory) never matched and Plan writes were denied. Also match absolute
rules against the resolved path; relative rules and last-match-wins order are
unchanged.

Fixes anomalyco#50241
Fixes anomalyco#46358

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Gev7ZaFyjYyAVymwC5cKkq
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@tommymedeiros

Copy link
Copy Markdown

Adding a v2.2.1 observation for the absolute-path case in this PR.

On macOS, in the native standalone TUI, I configured absolute read and edit deny rules for an inert file inside the project. The native read returned its contents. A valid native edit requested approval instead of being denied. I rejected the edit and independently checked that the file remained unchanged.

I then changed only the three canary resource strings to project-relative spelling, kept the same binary, model and project, and restarted the isolated TUI. The native read and edit of the denied fixture both returned policy errors without an approval prompt:

Permission denied: read
Permission denied: edit

The denied fixture's SHA-256 remained unchanged. The working resource string for both deny rules is:

.tmp/native-v2-self-cutover/synthetic/denied.txt

Sanitized excerpt from the agent configuration, with the project root replaced by a placeholder:

{
  "agents": {
    "build": {
      "permissions": [
        {
          "action": "read",
          "resource": "/absolute/path/to/project/.tmp/native-v2-self-cutover/synthetic/denied.txt",
          "effect": "deny"
        },
        {
          "action": "edit",
          "resource": "/absolute/path/to/project/.tmp/native-v2-self-cutover/synthetic/denied.txt",
          "effect": "deny"
        }
      ]
    }
  }
}

Separate headless debug agents output included those absolute rules on Build. That was not an inspection of the same private server used by the TUI.

The v2.2.1 sources appear to explain the result:

  • FileAccess.resolve returns a location-relative permission resource for an internal file, even when the tool input is absolute.
  • Permission.evaluate wildcard-matches that resource against the rule text without resolving an absolute rule against the location.

The relative spelling works in this configuration. I am reporting this as a v2.2.1 confirmation of the absolute-path case covered by this PR, rather than a TUI-specific permission bypass.

Limits: both variants retained project configuration and plugins, including the cmux OpenCode integration and a local shell guard. This is not a plugin-free minimal reproduction. Neither control used the shell guard to produce the native file-tool denials. No secret file was used, and I am not attaching raw configuration or credential captures.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

2 participants