AAK-HOOK-FAILOPEN-001: A PreToolUse hook lets the tool call through when it fails
- Severity
- HIGH
- Category
- Hook Injection (
hook-injection) - Scanner
agent_audit_kit/scanners/agent_gates.py- Auto-fixable
- No.
- SARIF name
HookFailOpen
What it detects
Claude Code blocks a tool call only on exit code 2 from a PreToolUse command hook. Any other failure (a crash, a missing interpreter, exit 1) is a non-blocking error and the call goes ahead. A Python hook with an uncaught exception exits 1, a shell hook under set -e exits with the failing command's code, a Node hook that throws exits 1, and a command line ending in || true hides every failure. So a gate that can refuse and can also fail opens when it fails, and the input that breaks it can come from the model. The rule also fires on settings that lean on permissions.ask with bypass mode still available (defaultMode: bypassPermissions, or a documented --dangerously-skip-permissions launch): the docs say an ask rule holds in every mode, and an open Claude Code report (issue 95741) measures it not prompting under bypass on 2.1.283 and 2.1.301. A hook that wraps its body and exits 2 or denies on any error, || exit 2 on the command line, onFailure set to block on the handler, and disableBypassPermissionsMode set to disable do not fire.
How to fix
Make any error block. On Claude Code 2.1.295 or later, set onFailure to block on the handler, which blocks on a crash, a missing script, an unexpected exit code or a timeout. On any version, wrap the whole script and exit 2 in the handler with the reason on stderr, or in shell add a trap on ERR that exits 2. Where a rule has to hold unattended, use a deny rule or a hook that denies instead of an ask rule, and turn bypass mode off with disableBypassPermissionsMode.
To confirm the finding is gone, report only this rule:
agent-audit-kit scan . --rules AAK-HOOK-FAILOPEN-001
Limitations
Reads PreToolUse command hooks in .claude/settings.json, .claude/settings.local.json, a plugin's hooks/hooks.json and a skill's frontmatter, and the script a command line names when it is a .py, .sh, .bash, .zsh, .js, .mjs, .cjs or .ts file inside the project. An inline command (jq ... | grep ...), bash -c '...', a PowerShell script, a path outside the project or built by a command, an http or prompt handler, another event and the user's own settings are not read. A script counts as a gate when it can refuse: it exits 2, or says deny, block or ask beside a decision. So a script whose refusal is made in a module it imports, or whose exit code is held in a name, is no gate here and does not fire, and a script that only allows or logs does not either. A shell script fires on set -e with no trap on ERR or EXIT that exits 2, and on exit 1; one without set -e that runs on past a failed jq with an empty variable fails open as well and does not fire. An import above the wrapping try is not counted. An exit within two lines of a usage message is read as a path a hook never takes. The rule over-reports in three ways it cannot tell apart: a script that guards every command by hand, one that fails open on purpose or enforces a preference rather than a policy, and one that prints a deny and then exits 1, which blocks. Node scripts are read for tokens, not parsed, so a comment or a string counts. The ask arm reads the two settings files, and a launch on a line naming claude in README.md, CONTRIBUTING.md, CLAUDE.md, AGENTS.md, Makefile, justfile or package.json, skipping a line that says never, avoid or do not; disableBypassPermissionsMode in managed or user settings is not seen. A source file over 512 KB is not read.
References
- OWASP Agentic Top 10: ASI02 (Tool Misuse and Exploitation)
- Adversa AI MCP Top 25 (AAK-defined ids): ADV-AUTH-01 (Missing Authentication)
All rules. This page is generated from the rule registry when the documentation is built; to change it, change the rule in agent_audit_kit/rules/builtin.py. To give the rule a hand-written write-up, add docs/rules/AAK-HOOK-FAILOPEN-001.md: the page then shows that text, with the registry reference appended under it.