Skip to content

fix: strip scoped allow rules for guarded tools from allowed_tools (#244) - #246

Open
FrundlesTian wants to merge 1 commit into
overwirehq:mainfrom
FrundlesTian:fix/scoped-allow-rules-bypass-guard
Open

FrundlesTian wants to merge 1 commit into
overwirehq:mainfrom
FrundlesTian:fix/scoped-allow-rules-bypass-guard

Conversation

@FrundlesTian

Copy link
Copy Markdown
Collaborator

Description

Scoped allow rules for guarded tools are now stripped from the allowed_tools handed to the SDK, so their calls reach can_use_tool and its boundary checks.

execute_command stripped GUARDED_TOOLS (and approval-gated tools) by exact name. A scoped rule such as Bash(mkdir:*), Read(//etc/**) or Write(*) in CLAUDE_ALLOWED_TOOLS was therefore passed through to the CLI, which pre-approves the calls it matches. Those calls skipped the APPROVED_DIRECTORY / Bash boundary checks and the interactive approval prompt. The fix matches each allow rule by the tool it names (the part before ().

Related Issue

Closes #244

This is a follow-up to #219, whose strip it completes, and it was found while working on #221 (whose PR, from fix/221-enforce-allowed-tools, enforces CLAUDE_ALLOWED_TOOLS). This PR is independent of that one and branches from main. The two touch neighbouring code, so whichever merges second may need a trivial rebase.

Type of Change

  • New feature
  • Bug fix
  • Breaking change
  • Documentation update

Behaviour

  • Default config (bare tool names): no change.
  • A scoped rule for a guarded or approval-gated tool: calls it used to pre-approve now go through can_use_tool, which allows them only if they pass validation (and, if gated, after the Allow/Deny prompt). Nothing becomes more permissive.
  • Scoped rules for unguarded tools (for example Grep(foo)) are left alone.
  • No SecurityValidator, or DISABLE_TOOL_VALIDATION=true: no change.

Testing

  • Tests added: Bash, Read, Write and Edit scoped rules are stripped; an unguarded scoped rule is kept; an approval-gated scoped rule is stripped; nothing is stripped without a validator
  • All tests pass (696 passed); black/isort/flake8 clean; no new mypy errors
  • Live session, bundled CLI 2.1.277, CLAUDE_ALLOWED_TOOLS=Read,Bash(mkdir:*), prompt "run mkdir -p sub":
    • before: gated_tools=['Read']. The Bash call ran and can_use_tool was never consulted.
    • after: gated_tools=['Read', 'Bash(mkdir:*)']. The Bash call reached can_use_tool (allowed, since it was inside the boundary).

Checklist

  • make format has been run
  • Code follows project style guidelines
  • Self-review completed
  • Documentation updated (SECURITY.md, CLAUDE.md)

🤖 Generated with Claude Code

ClaudeSDKManager.execute_command strips GUARDED_TOOLS (and approval-gated
tools) from the allowed_tools it hands the SDK so their calls reach
can_use_tool (overwirehq#219). It compared entries by exact name, so a scoped rule
such as Bash(mkdir:*), Read(//etc/**) or Write(*) in CLAUDE_ALLOWED_TOOLS
was passed through. The CLI pre-approves the calls a scoped rule matches,
so those calls skipped the APPROVED_DIRECTORY / Bash boundary checks and
the interactive approval prompt.

Match allow rules by the tool they name instead.

Verified against a live session (bundled CLI 2.1.277) with
CLAUDE_ALLOWED_TOOLS=Read,Bash(mkdir:*): before the fix `mkdir -p sub`
ran without can_use_tool being consulted; after it, the call reached the
callback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
  • CHANGELOG.md has no entry for this change. It alters which CLAUDE_ALLOWED_TOOLS rules reach the SDK: scoped rules like Bash(git:*) used to be passed through and are now stripped. This changes behaviour for existing configs, and the repo records each fix under [Unreleased] → ### Fixed. Add one.

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.

Scoped allow rules (e.g. Bash(git:*)) for guarded tools bypass the can_use_tool boundary checks

1 participant