Why it matters
Model output follows instructions planted in its input (prompt injection), so treat it as untrusted user input.
How to fix it
Never eval, exec or shell out model output. Parse it into a fixed structure (JSON schema, an enum of allowed actions), pass values to SQL as bound parameters, and let the template engine escape it.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
import subprocess
from openai import OpenAI
client = OpenAI()
def run_suggested_command(task):
resp = client.chat.completions.create(
model="gpt-4o-mini",
max_tokens=200,
messages=[{"role": "user", "content": task}],
)
command = resp.choices[0].message.content
subprocess.run(command, shell=True)import json
import subprocess
from openai import OpenAI
client = OpenAI()
ALLOWED = {"status": ["git", "status"], "log": ["git", "log", "-5"]}
def run_suggested_command(task):
resp = client.chat.completions.create(
model="gpt-4o-mini",
max_tokens=200,
messages=[{"role": "user", "content": task}],
)
action = json.loads(resp.choices[0].message.content)["action"]
print(action)
subprocess.run(ALLOWED["status"], check=True)What TrustIvan reads
Runs on repository scans of Python source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
- CWE-94: Improper Control of Generation of Code ('Code Injection')
- CWE-78: Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')
- CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
- CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
- OWASP Top 10 for LLM Applications LLM05:2025 Improper Output Handling
- OWASP Top 10 A03:2021 - Injection
Related checks
- Ai sdk use (Python)
PythonSeverity: Low
trustivan-python-ai-sdk-use - Llm prompt injection system from request input (Python)
PythonSeverity: Medium
trustivan-python-taint-llm-prompt-injection-system - CORS wildcard credentials (Python)
PythonSeverity: High
trustivan-python-cors-wildcard-credentials - Llm tool shell execution (Python)
PythonSeverity: Medium
trustivan-python-llm-tool-shell-execution - Weak RSA key (Python)
PythonSeverity: Medium
trustivan-python-weak-rsa-key - Llm unbounded output tokens (Python)
PythonSeverity: Low
trustivan-python-llm-unbounded-output-tokens
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation