Skip to content

fix(core): match file permission rules without case on macOS - #64626

Merged
neriousy merged 3 commits into
anomalyco:devfrom
knp-sap:macos-permission-case
Nov 18, 2026
Merged

neriousy merged 3 commits into
anomalyco:devfrom
knp-sap:macos-permission-case

Conversation

@knp-sap

@knp-sap knp-sap commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #64624

Type of change

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

What does this PR do?

Wildcard.match ignores case only on Windows. macOS volumes ignore case by default, so .OPENCODE/plugins/x.ts is the same file as .opencode/plugins/x.ts, but it did not match a .opencode/* rule.

Permission.evaluate and the organization tool.use policy hook now match the resources of the file actions (read, edit, and external_directory) without case on macOS. The list of file actions lives in Permission.pathActions, which the agent config also uses. Windows is unchanged. On macOS, shell commands and other resources still match with case. On a case-sensitive APFS volume, file rules now also match other spellings; that makes ask and deny rules stricter, but allow rules broader too.

No feature flag: this is a bug fix.

How did you verify your code works?

  • New tests in packages/core/test/permission.test.ts and packages/core/test/config/policy.test.ts. They fail on macOS without the fix; the new Wildcard.match option is checked on every platform.
  • On macOS, in packages/core: bun run script/test.ts (7562 pass, 0 fail), bun typecheck, and bun run typecheck:tsc.

Screenshots / recordings

Not a UI change.

Checklist

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

macOS volumes ignore case by default, so an edit to .OPENCODE/plugins/x.ts writes into the directory that config discovery loads as .opencode, yet escaped a .opencode/* rule. Match read, edit, and external_directory resources without case on macOS, as Windows already does for every rule; commands and other resources keep their case.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix works. With process.platform set to darwin, Permission.evaluate on the base allowed an edit to .OPENCODE/plugins/x.ts and a read of secrets.ENV under .opencode/* ask and *.env deny rules. With this change they are ask and deny, and shell commands still match with case. The permission tests pass and typecheck:tsc is clean. This was simulated on Linux, not run on a real Mac.

Public API: unchanged. Wildcard.match gains an optional third argument, which is internal and backwards compatible.

One gap worth closing in this pull request: organization tool.use deny policies are checked in packages/core/src/config/plugin/policy.ts through a separate Wildcard.match(${event.action}:${resource}, policy.resource) call. That call still matches with case on macOS, so a managed policy like read:*.env deny can still be bypassed with secrets.ENV, the same problem as #64624 in the layer organizations rely on most. It would be worth applying the same case rule there, ideally from one shared helper rather than a second copy of the file-action list. That list already exists as pathActions in config/plugin/agent.ts.

Comment thread packages/core/src/permission.ts Outdated
export type Error = BlockedError | CorrectedError

// macOS volumes ignore case by default, so `.OPENCODE/x` opens `.opencode/x`; rules for file paths must match it too.
const fileActions = new Set(["read", "edit", "external_directory"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list repeats pathActions in config/plugin/agent.ts (external_directory, read, edit). The managed tool.use policy hook in config/plugin/policy.ts also matches <action>:<path> resources with case on macOS, so organization deny policies can still be bypassed by spelling the path in another case. Could the list live in one place and be used by both checks?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done in da78cd8. Permission now exports pathActions and ignoresCase(action), and evaluate, the tool.use hook in config/plugin/policy.ts, and config/plugin/agent.ts all use them, so the list lives in one place. agent.ts still checks it against the tool names.

A new policy test checks that an organization read:*.env deny also blocks secrets.ENV on macOS; it fails without the change. I ran the full core suite on a real Mac.

The tool.use policy hook matched action:path resources with case, so an organization read:*.env deny could still be bypassed on macOS by reading secrets.ENV. Share the file action list and the case rule through Permission, and use them in evaluate, the policy hook, and the agent config.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My earlier point is resolved. The organization tool.use policy hook now matches file actions without case on macOS, and the list of file actions lives only in Permission.pathActions. config/plugin/agent.ts still checks it against the tool names when type-checking. With the platform set to darwin, a read:*.env deny now matches secrets.ENV, and shell policies still match with case. The permission and policy tests pass (146) and typecheck:tsc is clean. This was simulated on Linux, not run on a real Mac.

Public API: unchanged. Permission.pathActions, Permission.ignoresCase and the optional Wildcard.match argument are internal to packages/core.

No further concerns.

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new commit only changes how config/plugin/agent.ts reads Permission.pathActions, which is still type-checked against the tool names, so behavior is unchanged. The agent config, permission and policy tests pass and typecheck:tsc is clean. My earlier point about one shared list and the organization tool.use policies was addressed in da78cd8. Public API: unchanged. No further concerns.

@neriousy
neriousy merged commit 79bd2c6 into anomalyco:dev Nov 18, 2026
10 checks passed
vergeal added a commit to vergeal/aicraft that referenced this pull request Nov 22, 2026
…co#64626)

Adapted from upstream 79bd2c6. File actions (external_directory, read,
edit) ignore case on darwin, matching macOS volumes; commands keep their case.
@amrkmn amrkmn mentioned this pull request Nov 23, 2026
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

permission: file rules are case-sensitive on macOS, whose default file system is not

2 participants