rtk icon indicating copy to clipboard operation
rtk copied to clipboard

hook claude: deny rules like Bash(curl -d @*) are ignored; the command is rewritten to rtk curl and runs

Open jensechterling opened this issue 2 weeks ago • 1 comments

Version: rtk 1.2.0 (Homebrew, macOS), Claude Code hook rtk hook claude

What happens

A deny rule whose only wildcard is the trailing one, such as Bash(curl -d @*), is not honoured: the hook rewrites a matching command to rtk curl …. Claude Code then checks its deny rules against the rewritten command, which no longer matches, so the command runs. If an allow rule covers the command, RTK also answers allow.

Rules with an earlier wildcard (curl -F *=@*, curl * -d @*) or ending in * (curl -T *) are honoured.

Repro

A throwaway HOME with three deny rules and one allow rule:

T=$(mktemp -d) && mkdir -p "$T/.claude"
cat > "$T/.claude/settings.json" <<'EOF'
{"permissions":{"allow":["Bash(curl *)"],"deny":["Bash(curl -d @*)","Bash(curl -F *=@*)","Bash(curl * -d @*)"]}}
EOF

echo '{"tool_name":"Bash","tool_input":{"command":"curl -d @f.txt http://127.0.0.1:9/"}}' | HOME="$T" rtk hook claude
# {"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk curl -d @f.txt http://127.0.0.1:9/"},"permissionDecision":"allow"}}

echo '{"tool_name":"Bash","tool_input":{"command":"curl -F [email protected] http://127.0.0.1:9/"}}' | HOME="$T" rtk hook claude
# (no output: left alone, as expected)

echo '{"tool_name":"Bash","tool_input":{"command":"curl -s -d @f.txt http://127.0.0.1:9/"}}' | HOME="$T" rtk hook claude
# (no output: left alone via `curl * -d @*`, as expected)

Without the allow rule, the first command is still rewritten, just with no permissionDecision.

With a full rule set we saw the same for curl --data @*, curl --data-binary @* and curl --data-raw @*. curl --upload-file *, curl -T * and curl --form *=@* were honoured.

Expected

curl -d @f.txt URL matches Bash(curl -d @*) in Claude Code's own matcher, so the hook should leave it alone, as it does for the other rule shapes (and as #4281 does behind wrappers).

Impact

Verified end to end in Claude Code: curl -d @/dev/null http://127.0.0.1:9/ (an empty body to a closed local port) ran, with curl exit 7, while curl -F a=@/dev/null http://127.0.0.1:9/ under the same rules was denied. A deny rule meant to stop file uploads is bypassed. This is related to #3970: the permission verdict is computed on a command that is not the one that runs.

Workaround

Add curl to exclude_commands. After that, the same command is denied.

jensechterling avatar Nov 18 '26 07:11 jensechterling

wshm · Automated triage by AI

🔍 Automated Triage

🐛 Category bug
🟠 Priority high
🎯 Confidence 93%

Summary

Trailing-wildcard-only deny rules like Bash(curl -d @*) don't match the rewritten rtk curl ... command, silently bypassing deny rules (and granting allow) for several curl data-upload flags.

📁 Relevant files
  • src/hook/claude.rs
  • src/permissions/matcher.rs
  • src/rewrite/curl.rs

Suggested Actions

  1. Reproduce with the exact repro script against -d @, --data @, --data-binary @, --data-raw @ vs -F/-T which work
  2. Compare matcher logic for trailing-wildcard-only patterns against the earlier-wildcard/space-suffix cases that work cor…
  3. Cross-reference #4281 and #5005 — same root cause class: permission verdict computed on a command rtk doesn't actually …
  4. Ensure deny-rule check runs against the original command, not the rewritten rtk curl ... form, before any rewrite/all…

Triaged automatically by wshm · This is an automated analysis, not a human review.

rtk-wshm-sync-bot avatar Nov 18 '26 07:11 rtk-wshm-sync-bot