Skip to content

AAK-TAINT-003: Tool parameter flows to file open

Severity
HIGH
Category
Taint Analysis (taint-analysis)
Scanner
agent_audit_kit/scanners/taint_analysis.py, agent_audit_kit/scanners/typescript_pattern_scan.py
Auto-fixable
No.
SARIF name
TaintPathTraversal

What it detects

A @tool function parameter is used in open() or file path construction, enabling path traversal attacks. A pathlib.Path read at once for a part of its name (Path(p).suffix, .stem, .name) opens nothing and is not reported; only that inline read is skipped, so p = Path(path) and then p.suffix still is.

How to fix

Validate and sanitize file paths. Use os.path.realpath() and verify against allowed directories.

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

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

Limitations

Only functions decorated @tool, @mcp.tool, @server.tool, @langchain.tools.tool, @crewai.tool or @autogen.tool, and a low-level @<server>.call_tool() handler, are analysed, so a FastMCP instance under another name (@app.tool()) is skipped. open(...) and pathlib.Path(...) are reported only when the argument is a parameter or an item read from one (arguments["path"]) or, in a call_tool handler, a local holding one at most two assignments away, so open(os.path.join(ROOT, name)) is not, nor is a local in a @tool function (target = path). Path imported under another name (from pathlib import Path) is read through the file's imports, but not when the file also binds that name some other way anywhere, a method or another function's parameter included (def describe(Path)), or has a star import: the call is then matched by its spelling only. The TypeScript and JavaScript arm looks at fs.writeFile and appendFile calls only: a tool that reads a path with fs.readFileSync(path) is not reported. It reads a .js, .jsx, .mjs or .cjs file only when the file imports the SDK's server modules, registers a tool or handles CallToolRequestSchema, so a FastMCP server (server.addTool) is not reported. A JavaScript file is skipped as a bundle when its name holds .min., or when it is over 10,000 characters and its median non-blank line (the longer of the middle two, for an even number) is over 500 characters long or most of it is lines over 5,000 characters in which ( and ; make up at least 1%. So a one-line bundle of 10,000 characters or fewer is read, and a hand-written file most of whose text is one long line of inlined data with ; in it, such as a stylesheet or an SVG, is skipped, and its findings with it.

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