Skip to content

AAK-TAINT-005: Tool parameter flows to SQL query

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

What it detects

In Python, a @tool function parameter, or an item read from one, is passed as the whole query to cursor.execute(), connection.execute() or session.execute(), so the caller chooses the SQL that runs. The TypeScript and JavaScript arm reports a template literal with an interpolation passed to .query(), .execute() or .raw(), a string literal concatenated into .query() or .execute(), and Prisma's $queryRawUnsafe and $executeRawUnsafe; the Rust arm, a sql!, query! or query_as! macro given a format! string or a concatenation that starts with a bare name (sql!(base + id)).

How to fix

Use parameterized queries. Never use f-strings or .format() for SQL.

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

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

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. The Python arm reports cursor.execute, connection.execute and session.execute only when a parameter, or an item read from one, is the whole argument, that is, a caller-supplied query, and not when a local holds it, even in a call_tool handler (sql = arguments["sql"], then cursor.execute(sql)). A query built from the parameter, whether by an f-string (cursor.execute(f"SELECT * FROM notes WHERE title = '{title}'")), .format(), % or +, the usual shape of SQL injection, is not reported, and neither is the same call on a variable under another name (conn.execute(query)). The TypeScript and JavaScript arm reads the template literal or the concatenation on the call's own line, so a query built into a variable first (db.query(sql)), or one whose ${ falls on a later line, 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. 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-005.md: the page then shows that text, with the registry reference appended under it.