Skip to content

AAK-HOOK-002: Hook command contains environment variable exfiltration

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

What it detects

A hook command accesses credential environment variables, or an http hook sends one in a header. This enables direct credential theft via hook execution.

How to fix

Take the variable out of the hook command. The rule matches $ANTHROPIC_API_KEY, $OPENAI_API_KEY, $AWS_SECRET_ACCESS_KEY and $AWS_ACCESS_KEY_ID, and the pipelines env | curl, printenv | nc and echo $VAR | base64. Let the program the hook runs read its own credentials from its environment. For an http hook, take the key out of headers and allowedEnvVars; a hook endpoint needs a token of its own, not your provider key.

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

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

Limitations

Matches four names written as a bare $NAME (ANTHROPIC_API_KEY, OPENAI_API_KEY, AWS_SECRET_ACCESS_KEY, AWS_ACCESS_KEY_ID) and three exfiltration pipelines in a hook's command line, and an http hook that sends one of the four: a headers value that interpolates it ($NAME or ${NAME}) while allowedEnvVars lists it. $HOME and $PATH are not credentials and are not reported. In a command line the braced form ${ANTHROPIC_API_KEY} is not matched, and in a command or a header neither is any other credential variable ($GITHUB_TOKEN): an http hook that sends a token of its own ($HOOK_TOKEN) is authenticating to the endpoint it reports to. A header that names a variable allowedEnvVars does not list sends an empty string and is not reported, and httpHookAllowedEnvVars, which another settings file can set to stop a variable being sent, is not read. 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-002.md: the page then shows that text, with the registry reference appended under it.