How to fix: User Input Concatenated Directly Into an LLM Prompt
Request-derived data is interpolated directly into an LLM API call's prompt/message content with no visible isolation or sanitization.
Why it matters
An attacker can craft input that overrides the intended system instructions (prompt injection), potentially exfiltrating other users' data, bypassing content policies, or making the model take unintended actions if it has tool access.
AI-scaffolded backends commonly template the user's message straight into the prompt string sent to the model. Without structural separation between trusted instructions and untrusted user content, the model has no reliable way to distinguish 'developer instruction' from 'attacker-supplied text masquerading as an instruction'.
How to fix it
- 1Keep user input in its own message role (e.g. the 'user' role) separate from the system prompt, rather than string-templating it into instructions.
- 2Treat any tool/function-calling output as untrusted and validate before acting on it.
- 3Apply an output-side check before taking irreversible actions based on model output derived from user text.
Code examples
Keep user content in its own message role
const response = await client.messages.create({
system: 'You are a support assistant. Only answer questions about billing.',
messages: [{ role: 'user', content: userInput }],
});
// Do not template userInput into the system prompt stringReferences
Detected automatically by VulnRadar. The check id is vibe-prompt-injection-risk, stable across every scan so you can filter or diff on it.
More ai code checks
- LowGeneric Error Messages Leak No Context
- MediumTODO/FIXME Security Note in Response
- Higheval() Usage in Page Scripts
- HighSSL Certificate Verification Disabled
- HighMath.random() Used for Security Tokens
- CriticalHardcoded Credential in Authentication Logic
- CriticalJWT 'none' Algorithm Accepted
- CriticalSQL String Concatenation Pattern Detected
Questions
- How severe is User Input Concatenated Directly Into an LLM Prompt?
- VulnRadar rates this medium severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
- Does VulnRadar check for this automatically?
- Yes. It runs as part of every scan under the check id vibe-prompt-injection-risk, which stays the same between runs so you can filter, diff, or gate CI on it.
Missing a check?
The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.