Repository navigation
fix(core): match file permission rules without case on macOS - #64626
Conversation
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.
There was a problem hiding this comment.
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.
| 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"]) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Issue for this PR
Closes #64624
Type of change
What does this PR do?
Wildcard.matchignores case only on Windows. macOS volumes ignore case by default, so.OPENCODE/plugins/x.tsis the same file as.opencode/plugins/x.ts, but it did not match a.opencode/*rule.Permission.evaluateand the organizationtool.usepolicy hook now match the resources of the file actions (read,edit, andexternal_directory) without case on macOS. The list of file actions lives inPermission.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?
packages/core/test/permission.test.tsandpackages/core/test/config/policy.test.ts. They fail on macOS without the fix; the newWildcard.matchoption is checked on every platform.packages/core:bun run script/test.ts(7562 pass, 0 fail),bun typecheck, andbun run typecheck:tsc.Screenshots / recordings
Not a UI change.
Checklist