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 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 render it as text (textContent, JSX children) or through a sanitiser such as DOMPurify.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
import OpenAI from "openai";
const client = new OpenAI();
export async function renderAnswer(el, question) {
const resp = await client.chat.completions.create({
model: "gpt-4o-mini",
max_tokens: 300,
messages: [{ role: "user", content: question }],
});
el.innerHTML = resp.choices[0].message.content;
}import OpenAI from "openai";
const client = new OpenAI();
export async function renderAnswer(el, question) {
const resp = await client.chat.completions.create({
model: "gpt-4o-mini",
max_tokens: 300,
messages: [{ role: "user", content: question }],
});
el.textContent = resp.choices[0].message.content;
}What TrustIvan reads
Runs on repository scans of JavaScript 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 (JavaScript)
JavaScriptSeverity: Low
trustivan-javascript-ai-sdk-use - Llm prompt injection system from request input (JavaScript)
JavaScriptSeverity: Medium
trustivan-javascript-taint-llm-prompt-injection-system - Bcrypt low rounds (JavaScript)
JavaScriptSeverity: Medium
trustivan-javascript-bcrypt-low-rounds - Llm unbounded output tokens (JavaScript)
JavaScriptSeverity: Low
trustivan-javascript-llm-unbounded-output-tokens - World writable permissions (JavaScript)
JavaScriptSeverity: Medium
trustivan-javascript-world-writable-permissions - Electron node integration (JavaScript)
JavaScriptSeverity: High
trustivan-javascript-electron-node-integration
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