GeezerVison is showing github.com — permission: grep shows lines from files whose read rule asks or denies · Issue #64623 · anomalyco/opencode
permission: grep shows lines from files whose read rule asks or denies #64623DescriptionDescription
The grep tool checks its permission against the search pattern only. It then searches with --hidden and quotes the matching lines of every file, without checking the read rules for those files.
With the default agent rules, reading *.env asks, but grep is allowed. So grep shows the contents of a .env file without asking. A read deny rule is bypassed the same way.
Earlier reports of this were closed by the stale bot: #17073 and #29674.
Plugins
None needed to reproduce.
OpenCode version
2.3.0, and current dev
Steps to reproduce
- In a directory that is not a Git repository, create
.env containing API_KEY=example-value.
- Ask the agent to read
.env. OpenCode asks for permission.
- Ask the agent to grep for
API_KEY. The result shows API_KEY=example-value without asking.
Operating System
macOS 27.2.1 Activityopencodejr commented on Nov 18, 2026 Thanks for the clear report and for the reproduction steps.
I think this is a duplicate of #64059. It reports the same gap: grep (and glob) check their permission only against the search pattern, so a read rule on *.env that asks or denies is bypassed when the agent searches file contents. The code agrees: packages/core/src/tool/plugin/grep.ts asserts resources: [input.pattern] and does not check read for the files it matches.
The tools docs describe this as current behaviour: grep is checked "with the requested pattern, not the search path". The permissions page says the same. That is why #64059 is being tracked as a change to how these permissions work.
Possible duplicates and related issues, ordered from most to least likely:
- grep and glob assert their pattern as the permission resource, so path-based policy is impossible #64059: the same problem,
grep/glob bypassing path-based read rules such as *.env. Its discussion also covers the directory-search case you describe, where each matched file would need to be checked.
- 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.
- [FEATURE]: Protect .env files in grep/glob results, not just direct read #17073 and The Read, Glob, and Grep tools do not verify these rules before execution. #29674: the earlier reports you mentioned, closed for inactivity.
I'm closing this issue now as a duplicate of #64059. Please add your details there, and consider linking your PR #64625 from that issue so maintainers see it together with the discussion. If you think this is a different problem, replying here reopens this issue.
knp-sap commented on Nov 18, 2026 ContributorAuthor More actions I think this is a bug rather than a duplicate of #64059. With the default agent rules, reading *.env asks, but grep is allowed and searches hidden files, so it returns .env contents that the defaults are meant to protect. No custom configuration is needed, and your review of #64625 reproduced it on the base.
#64059 asks for path-based rules for grep and glob in general. #64625 is the narrow fix: it leaves out matches from files that the existing read rules don't allow, and it doesn't change glob or the permission vocabulary. opencodejr commented on Nov 18, 2026 Thanks for explaining, and for the PR.
You're right that no custom configuration is needed. By default, every agent asks before a read of *.env, but every other action is allowed, grep included, so a search can return .env lines without a prompt. Nobody disputes that this happens.
I still think #64059 is the right place to track it. The tools docs and the permissions page describe this as current behaviour: grep is checked "with the requested pattern, not the search path". The defaults only cover read actions. So making grep respect read rules is a change to how the permission works, and #64059 is tracking that change. That issue also covers your exact case: its discussion notes that a directory search would need each matched file checked, which is what #64625 does.
#64625 now describes itself as "the grep half" of #64059, so maintainers will see it there as the narrow option. Whether it lands as a fix to the defaults or as part of a wider change to grep and glob is their call. If a maintainer decides this is a bug in the default rules and should be tracked separately, they can reopen this issue.
In the meantime, the shipped explore agent and any agent you set up with your own rules can deny grep or set it to ask if you want to keep it away from .env files.
opencodejr commented on Nov 18, 2026 Closing this now as a duplicate of #64059, which tracks making grep (and glob) respect path-based read rules such as the default *.env ask. Your case, a directory search that returns .env lines without asking, is covered there. Your PR #64625 now describes itself as the grep half of that issue, so maintainers will consider it there.
A correction to my last reply: the shipped explore agent allows grep, so it doesn't keep grep away from .env files. An agent with your own rules can set grep to ask or deny.
Thanks for the clear report and the fix. If something here isn't covered by #64059, please open a new issue.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|