Skip to content

AAK-HOOK-003: Hook command writes to files outside project directory

Severity
HIGH
Category
Hook Injection (hook-injection)
Scanner
agent_audit_kit/scanners/hook_injection.py
Auto-fixable
No.
SARIF name
HookWriteOutsideProject

What it detects

A hook command writes to paths outside the project boundary, which can modify system configs, plant persistence, or stage exfiltration.

How to fix

Write only inside the project: use project-relative paths for anything the hook creates or changes. The rule reports a write to a path under /tmp, ~, /etc, /var, /usr or /home, such as a > redirect, tee, cp, mv, sed -i, curl -o or tar; calling a tool by its absolute path, or reading such a path, does not fire it.

To confirm the finding is gone, report only this rule:

agent-audit-kit scan . --rules AAK-HOOK-003

Limitations

Reads the hook's command line as shell commands and reports one that writes a path under /tmp, ~, /etc, /var, /usr or /home: a > or >> redirect, tee, mkdir, touch, chmod, chown or truncate on it, the destination of cp, mv, install or ln, sed -i or perl -i, curl -o, wget -O or -P, dd of=, or tar creating or extracting there, also inside sh -c and after sudo or env. A command that only names such a path (cd /tmp/build, reading ~/.config) is not reported, and neither is deleting one. A path reached through $HOME or a relative climb (../../shared/out.json) is not matched, nor is a write made by a script the hook runs. Hooks a plugin declares in .claude-plugin/plugin.json and hooks in a subagent's frontmatter are not read.

References


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-003.md: the page then shows that text, with the registry reference appended under it.