Summary
grep and glob assert only their pattern as the permission resource. The path they read is resolved and passed to hooks as metadata, but it is never part of the permission decision, so path-based policy is impossible for these tools.
// packages/core/src/tool/plugin/grep.ts:87-99
yield* permission.assert({
action: name, // "grep"
resources: [input.pattern], // <-- the regex, not the path
save: ["*"],
metadata: { root: ".", path: input.path, include: input.include, ... },
...Permission.invocation(context),
})
// packages/core/src/tool/plugin/glob.ts:69-81
yield* permission.assert({
action: name, // "glob"
resources: [input.pattern], // <-- the glob, not the path
save: ["*"],
metadata: { root: searchPath ?? ".", path: searchPath, hidden: input.hidden, limit: input.limit },
...Permission.invocation(context),
})
Contrast with read, which asserts the resolved path (file-access.ts:149-154):
yield* permission.assert({
action: "read",
resources: [target.resource],
save: ["*"],
...Permission.invocation(context),
})
Why it matters
A rule set that restricts reads by path cannot restrict grep/glob the same way:
{ "permissions": [
{ "action": "read", "resource": "*.env", "effect": "ask" },
{ "action": "read", "resource": "*", "effect": "allow" },
{ "action": "grep", "resource": "*", "effect": "allow" },
{ "action": "glob", "resource": "*", "effect": "allow" }
] }
grep with pattern: "SECRET", path: "config/.env" is allowed by the grep: * rule and returns the file's matching lines. The read: *.env ask never fires, because grep never asserts read and never puts the path in a resource. The same holds for glob with path: "config" — it enumerates .env filenames.
authorizeExternal is called on the resolved target, so outside-the-workspace access is gated. The gap is inside the workspace, where path-based rules are the only defence.
Why metadata does not close it
metadata.path and metadata.root are passed to the permission.evaluate hook (permission.ts:190-198), so a plugin can read them. But:
- The built-in
configured/savedRules evaluation in permission.ts never looks at metadata — the decision is evaluate(action, resource, rules) per resource only.
- The one in-tree consumer of the evaluate hook (
config/plugin/policy.ts:98-113) matches on `${event.action}:${resource}` and ignores metadata entirely.
- So out of the box, a user writing
permissions in config has no way to express "grep may not touch *.env". It requires writing a plugin.
Options
Maintainers' call — filing this rather than picking one.
A. Assert the path as an additional resource (or a second assertion).
yield* permission.assert({
action: name,
resources: [input.pattern, target.resource], // pattern + resolved path
save: ["*"],
metadata: { ... },
...Permission.invocation(context),
})
Or a separate read assertion on the resolved target, mirroring authorizeRead:
yield* permission.assert({ action: "read", resources: [target.resource], save: ["*"], ...Permission.invocation(context) })
- Pros: path policy becomes expressible with existing rules; consistent with
read; small diff.
- Cons:
resources would mix two different kinds of thing (a regex and a path) under one action, so a single rule cannot distinguish them — { action: "grep", resource: "*.env" } would also match a pattern containing .env. The separate read assertion avoids that ambiguity and reuses the existing read rules, but it makes grep/glob prompt whenever read would, which is a behaviour change for configs that ask on read.
- Also needs a decision on
save semantics: ["*"] on the pattern is harmless, but ["*"] on a path would save a workspace-wide allow on "always".
B. Document the limitation.
State in the permissions docs that grep and glob are gated by pattern only, and that path restriction requires external_directory rules or a plugin reading metadata.path.
- Pros: no behaviour change, no schema questions.
- Cons: leaves a real hole for anyone who assumes
read rules cover content search.
C. A dedicated path action.
e.g. assert { action: "search", resources: [target.resource] } alongside the pattern, so search rules are separate from both grep/glob pattern rules and read rules.
- Pros: unambiguous, no collision with pattern matching.
- Cons: new action name in the public permission vocabulary; needs docs and a migration note.
Related
Reproduction
packages/core on dev at d432a06:
{ "permissions": [
{ "action": "grep", "resource": "*", "effect": "allow" },
{ "action": "read", "resource": "*.env", "effect": "deny" }
] }
Then call grep with { "pattern": "API_KEY", "path": ".env" }. It returns the matching lines; no read assertion is made and no permission request is raised.