Skip to content

fix: strip scoped allow rules for guarded tools so they reach can_use_tool - #247

Open
shubhranillayek wants to merge 3 commits into
overwirehq:mainfrom
shubhranillayek:fix/scoped-allow-rules-guarded-tools
Open

shubhranillayek wants to merge 3 commits into
overwirehq:mainfrom
shubhranillayek:fix/scoped-allow-rules-guarded-tools

Conversation

@shubhranillayek

Copy link
Copy Markdown

Description

ClaudeSDKManager.execute_command strips guarded tools (and tools gated behind interactive approval) from allowed_tools so the CLI routes those calls through can_use_tool instead of pre-approving them (#219). The strip compared entries by exact name, so a scoped allow rule such as Bash(git:*) or Read(//etc/**) never matched Bash/Read in the strip set and was passed through to the CLI. The CLI pre-approved every call the rule matched, and the boundary checks (and the Telegram approval prompt) never ran -- a rule written to narrow what Claude may do silently removed a security layer.

This change matches allow rules by the tool they name -- the part before ( -- when deciding what to strip, via a small _allow_rule_base_name helper. Stripping a scoped rule does not loosen anything: matching calls now reach the callback, which allows them only if they pass validation, the same treatment bare tool names already get since #219.

Related issue

Closes #244

Type of change

  • Bug fix
  • New feature
  • Breaking change (documented in CHANGELOG under "Changed" or "Removed")
  • Documentation or tooling only

How it was tested

  • Tests added or updated
  • make test and make lint pass locally
  • Tested by hand against a running bot: not run against a live bot -- verified through the unit suite instead. Three new regression tests in tests/unit/test_claude/test_scoped_allow_rules.py cover scoped rules for guarded tools (stripped), scoped rules for approval-gated tools (stripped), and scoped rules for unguarded tools (kept). Full unit suite: 692 passed. black, isort and flake8 clean on the changed files.

Checklist

  • One concern per PR; unrelated changes are split out
  • CHANGELOG.md has an entry under [Unreleased]
  • If pyproject.toml dependencies changed, poetry lock was run and the updated poetry.lock is committed (no dependency changes in this PR)
  • Documentation updated (README.md, docs/, .env.example, CLAUDE.md) where settings or commands changed (no settings or commands changed)
  • New settings default to current behaviour (no new settings)
  • If AI tools helped write this change, I reviewed every line and the hand-testing above is mine

…_tool

The strip added for overwirehq#219 compared allow rules by exact name, so a scoped rule like Bash(git:*) never matched Bash in the strip set and was passed to the CLI, which pre-approved matching calls and skipped the can_use_tool boundary checks (and the interactive approval prompt). Match rules by the tool they name -- the part before the scope -- instead.

Refs overwirehq#244
@github-actions

Copy link
Copy Markdown

No blocking findings at this head.

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