System prompt is not exposed in API responses
Why it matters
Returning the raw AI provider response object to the client exposes your system prompt—the complete set of instructions governing your AI's behavior—to anyone who inspects the network response. OWASP LLM01:2025 lists system prompt disclosure as a direct attack enabler: once an attacker knows your exact instructions, they can craft targeted overrides, identify specific restrictions to circumvent, and reverse-engineer your application's business logic. MITRE ATLAS AML.T0051 classifies this as reconnaissance that precedes targeted injection. CWE-200 covers the broader information exposure class. In some AI SDK versions, the response object echoes the full messages array including the system role—returning completion directly rather than completion.choices[0].message.content leaks this data to every user.
Severity rationale
Critical because system prompt disclosure gives attackers the exact blueprint needed to craft targeted injection attacks, collapsing the attacker's effort from exploratory probing to direct exploitation.
Remediation
Extract only the assistant's reply content from the completion object. Return nothing else to the client.
// src/app/api/chat/route.ts
const completion = await openai.chat.completions.create({
model: 'gpt-4o',
messages // system prompt is in here — never send this array to the client
})
// Return only the assistant message text
const assistantReply = completion.choices[0]?.message?.content ?? ''
return Response.json({ message: assistantReply })
// Do NOT return: completion, messages, or any field that includes the system prompt
Also audit your error handling (see the no-prompt-in-errors check)—a catch block that returns error.response.data from the OpenAI SDK can echo the request payload including the system message.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the AI Prompt Injection Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-200 — Exposure of Sensitive Information to an Unauthorized Actor
- owasp-llm:2025 · LLM01 — Prompt Injection
- mitre-atlas:v4 · AML.T0051 — LLM Prompt Injection
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-prompt-injection·automated