Lessons · LLM02: Sensitive Information Disclosure · error
The model can repeat anything it was given, including your keys.
Caught by secrets-in-prompt-context · CWE-200, CWE-532
An environment variable (an API key, a database URL, an internal token) is pasted into the system prompt or a message so the model can use it.
Everything in the prompt is text the model can quote back. There is no part of a prompt the model is unable to repeat.
Prompts also get logged: by your app, by your observability tools, and by the provider. A secret in a prompt is a secret in all of those logs.
Your assistant can look up orders, so the system prompt includes the internal API token it should use.
system: `You can call the orders API with token ${process.env.ORDERS_TOKEN}.`
The cost: The secret is exposed to every user who asks the right question, and to every log that stores prompts.
Paste this into Claude Code, Cursor, or whatever wrote the code. When llm-audit finds the mistake in your project, npx llm-audit prompt gives you the same prompt with every file and line filled in.
Fix this in my project: a secret from an environment variable is placed inside the prompt.
Please:
1. Remove the secret from the prompt entirely.
2. Keep the credential in server code: the API client config or request headers.
3. If the model needs to act on a resource, give it a tool. The tool runs on the server and uses the secret there. The model only sees the result.
4. After the fix, rotate the secret, because it may already be in logs.
Show me the diff.A prompt that looks for the same mistake everywhere else, without changing anything yet.
Check this project for secrets that reach my AI model's prompt, before I ship it.
Look for:
- process.env values used in a system prompt, a prompt string, or a message.
- Tokens, passwords, connection strings, or internal URLs written into prompt text.
- Logging of full prompts, which would also log anything secret in them.
For each one, give me the file and line and say what someone could do if the model repeated it. Do not change any code yet.npx llm-audit scan
Runs on your machine with Semgrep. Nothing is uploaded.