Skip to content

fix(permission): **/.env* deny rule now blocks root-level .env files (issue #29674)#29717

Closed
Qingzhou-Joshua wants to merge 6 commits into
anomalyco:devfrom
Qingzhou-Joshua:fix/permission-deny-env-files
Closed

fix(permission): **/.env* deny rule now blocks root-level .env files (issue #29674)#29717
Qingzhou-Joshua wants to merge 6 commits into
anomalyco:devfrom
Qingzhou-Joshua:fix/permission-deny-env-files

Conversation

@Qingzhou-Joshua

Copy link
Copy Markdown

Summary

Fixes #29674 — configuring { "read": { "**/.env*": "deny" } } in
opencode.jsonc had no effect because of three independent bugs:

  • **/ wildcard bug: **/ was compiled to (.*/)+ (one-or-more) instead
    of (.*/)? (zero-or-more), so **/.env* never matched .env at the
    project root
    without checking read deny rules
  • grep tool not filtering results: ripgrep content matches were returned
    without checking read deny rules

Changes

  • packages/core/src/util/wildcard.ts — fix **/ expansion order
  • packages/opencode/src/tool/tool.ts — add evaluate() to Tool.Context
    for silent permission checks
  • packages/opencode/src/session/tools.ts — implement evaluate() in context
    factory
  • packages/opencode/src/tool/glob.ts — filter results against read deny
    rules
  • packages/opencode/src/tool/grep.ts — filter results against read deny
    rules

Tests

  • 4 new wildcard unit tests
  • 8 new integration tests covering the full issue scenario
  • All 17 relevant tests pass ✅

joshuaachen and others added 6 commits May 28, 2026 15:25
`**/` now correctly matches root-level files (e.g. `**/.env*` matches
`.env`). The placeholder is expanded after `*` and `?` substitution to
avoid those passes corrupting the already-expanded regex fragment.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a new `evaluate()` method to Tool.Context that silently checks a
permission rule against the merged agent+session ruleset without
triggering the ask UI. This enables glob and grep tools to filter out
denied file paths from their results in a future change.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…co#29674)

After ripgrep collects glob results, filter out any file whose path
relative to the worktree matches a "read" deny rule via ctx.evaluate().
This prevents denied files (e.g. .env) from leaking into glob output
even when the global glob permission is allowed. Also adds a test file
and updates the glob test mock context with the evaluate() method.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…co#29674)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…y rule enforcement

Appends a new describe block with three integration tests that verify:
1. User config deny rule blocks .env at root for read
2. User config deny rule blocks .env in subfolders for read
3. Default agent rules handle .env files via pattern matching

These tests exercise the complete fix for issue anomalyco#29674, which includes:
- Wildcard fix for **/ to match root-level files
- glob tool filtering against read deny rules
- grep tool filtering against read deny rules

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions github-actions Bot added the needs:compliance This means the issue will auto-close after 2 hours. label May 28, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Based on the search results, I found one potentially related PR:

Related PR:

Why it's related: PR #28689 also addresses wildcard pattern matching in permissions, specifically the ** globstar support and * behavior with path separators. Since the current PR (29717) fixes a **/ wildcard compilation bug that was preventing .env deny rules from working, this prior PR likely laid groundwork for globstar support that may be relevant to the fix.

No exact duplicate PRs found addressing the same issue #29674.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

@github-actions github-actions Bot removed the needs:compliance This means the issue will auto-close after 2 hours. label May 28, 2026
@github-actions github-actions Bot closed this May 28, 2026
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.

The Read, Glob, and Grep tools do not verify these rules before execution.

1 participant