GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — grep and glob assert their pattern as the permission resource, so path-based policy is impossible · Issue #64059 · anomalyco/opencode

grep and glob assert their pattern as the permission resource, so path-based policy is impossible #64059

New issue
Copy link
New issue
Copy link
Open
Open
grep and glob assert their pattern as the permission resource, so path-based policy is impossible#64059
Copy link
Labels
area/coreAgent loop, tools and configtype/featureNew behaviour or an improvementversion/v2OpenCode 2.x

Description

@kayceepeece
kayceepeece
opened on Nov 15, 2026
Issue body actions

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

  • fix(core): assert shell redirect targets as file writes #64058 — the same class of gap in shell: a redirect target stayed inside the command resource, so an allow rule like git status * swallowed > /path and the write was never asserted. Fixed there by extracting redirect targets and asserting them as edit.

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.

Activity

  1. opencodejr commented on Nov 15, 2026

    @opencodejr
    opencodejrBot
    on Nov 15, 2026
    Contributor
    More actions

    Thanks for the detailed write-up and for laying out the options.

    You're asking for grep and glob to be covered by path-based permission rules, so that a rule like read: *.env can't be bypassed by searching file contents or listing filenames inside the workspace.

    Right now this is how the tools are documented to work: the tools docs say grep is checked "with the requested pattern, not the search path", and glob "with the requested pattern as its resource". The permissions page says the same. So I've labelled this as a feature request rather than a bug. Maintainers will consider it, along with the options you described.

    One point for whichever option is chosen: when the search path is a directory (for example path: "."), the files actually read are never passed to the permission check. Checking the search path, as in option A, would still miss a .env inside that directory. Covering that case would mean checking each matched file.

    Related issues:

    • [FEATURE]: Protect .env files in grep/glob results, not just direct read #17073: the same request from earlier (protect .env from grep/glob results, not just direct reads), closed automatically for inactivity
    • bash: recursive file-reading commands (grep -r, rg, ls -R) bypass filename-pattern deny rules #56545: the same kind of gap for recursive shell commands (grep -r, rg, ls -R) and filename deny rules
    • permissions: compound shell commands drop redirection, so an allowed command becomes an unprompted file write #52083: shell redirection targets missing from permission resources (the class of gap you mention from fix(core): assert shell redirect targets as file writes #64058)
  2. opencodejr
    added
    area/coreAgent loop, tools and config
    type/featureNew behaviour or an improvement
    version/v2OpenCode 2.x
    on Nov 15, 2026
  3. opencodejr
    marked permission: grep shows lines from files whose read rule asks or denies #64623 as a duplicate of this issue on Nov 18, 2026
  4. knp-sap commented on Nov 18, 2026

    @knp-sap
    knp-sap
    on Nov 18, 2026
    Contributor
    More actions

    I opened #64625 for the grep half of this. As noted above, a directory search never passes the matched files to the permission check, so the PR checks each matched file's read rule with permission.allows and returns matches only from files that are allowed without asking. It adds no prompts and no new action. The output says how many files were left out, so the model can still use read, which asks, when it needs one of them.

    glob is unchanged because it only lists names. I can extend it the same way if you want that.

  5. opencodejr
    unmarked permission: grep shows lines from files whose read rule asks or denies #64623 as a duplicate of this issue on Nov 18, 2026
  6. opencodejr
    marked permission: grep shows lines from files whose read rule asks or denies #64623 as a duplicate of this issue on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreAgent loop, tools and configtype/featureNew behaviour or an improvementversion/v2OpenCode 2.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.