AAK-MCP-ARGV-TOCTOU-001: Argv re-built after allowlist approval before spawn (command-injection TOCTOU)
- Severity
- HIGH
- Category
- MCP Configuration (
mcp-config) - Scanner
agent_audit_kit/scanners/argv_toctou.py- Auto-fixable
- No.
- SARIF name
ArgvAllowlistToctou
What it detects
A command / argv buffer is approved against an allow/deny list and then reassigned, re-split (shlex.split / .split()), re-joined, concatenated, .extend()/.push()-ed, or otherwise rebuilt before it is passed to a process-spawn sink (subprocess.run/Popen/call, os.exec* / os.system; Node child_process.spawn/exec/execFile, execa) — with no re-validation between the mutation and the spawn. The executed command shape therefore differs from the one that was approved, so an attacker-controlled argv can pass the allowlist check and still reach the shell. Anchor: CVE-2026-53822 (CVSS 8.8) — OpenClaw before 2026.5.18 contained a command injection where the shell wrapper argv could change between approval and execution. CWE-77 (Command Injection) chained to CWE-367 (Time-of-check Time-of-use Race Condition). Detected as an ordered approve -> mutate -> exec data flow on the same command variable; distinct from AAK-SSRF-TOCTOU-001 (a URL allow-list DNS-rebind TOCTOU, not command spawn).
How to fix
Validate the exact argv array that will be executed, and execute that same immutable buffer — never re-parse, re-split, re-join, or append to the command after the allowlist check. If a transform is unavoidable, re-run the allowlist/deny check on the final argv immediately before spawning, pass an explicit argv list (never a shell string) with shell=False, and freeze the approved value (e.g. a tuple) so it cannot be mutated. Pin OpenClaw >= 2026.5.18.
To confirm the finding is gone, report only this rule:
agent-audit-kit scan . --rules AAK-MCP-ARGV-TOCTOU-001
Limitations
In Python a spawn is recognised by its spelling: subprocess.run, call, Popen, check_call or check_output, or os.system, os.popen, os.exec*, os.spawnv, os.spawnl or os.spawnvp. A function imported by name (from subprocess import run) or a module alias (import subprocess as sp) is missed. In TypeScript only the first argument of spawn, exec, execFile, execa or their Sync forms is followed, so an argv array passed second (spawn(bin, args)) and changed after the check is not.
References
- CVE: CVE-2026-53822
- OWASP MCP Top 10: MCP05:2025 (Command Injection & Execution)
- OWASP Agentic Top 10: ASI05 (Unexpected Code Execution (RCE))
- Adversa AI MCP Top 25 (AAK-defined ids): ADV-INJECT-07 (Tool Param SQL Injection)
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-MCP-ARGV-TOCTOU-001.md: the page then shows that text, with the registry reference appended under it.