Prompt template uses parameterized construction, not string concatenation
Why it matters
Scattered ad-hoc prompt construction across route handlers makes it structurally impossible to audit what user input reaches the model. When prompt building is decentralized, a single developer's shortcut—interpolating a query param into the system message in one handler—creates an injection vulnerability that is invisible to reviewers looking at other handlers. CWE-1427 and OWASP LLM01:2025 both identify inadequate prompt construction as a root-cause enabler. Centralized, typed prompt builders create a single auditable boundary: every change to what enters a prompt is visible, testable, and reviewable in one place. For teams under NIST AI RMF governance, demonstrating a controlled prompt construction process requires exactly this kind of centralization.
Severity rationale
Low because the risk is architectural—it doesn't directly expose a vulnerability but makes it significantly harder to detect and prevent injection at other check points.
Remediation
Create a dedicated prompt construction module (src/lib/prompts.ts) that accepts typed parameters and returns a fully-formed messages array. All AI call sites import from this module; no prompt building happens inline.
// src/lib/prompts.ts
import type { ChatCompletionMessageParam } from 'openai/resources'
const SYSTEM_PROMPT = `You are a helpful assistant for Acme. [full instructions]`
export function buildChatMessages(params: {
userMessage: string
context?: string // pre-sanitized retrieval context only
}): ChatCompletionMessageParam[] {
return [
{ role: 'system', content: SYSTEM_PROMPT },
...(params.context
? [{ role: 'system' as const, content: `<context>\n${params.context}\n</context>` }]
: []),
{ role: 'user', content: params.userMessage }
]
}
The TypeScript signature acts as a contract: adding a new variable input requires an explicit parameter, making it visible in code review rather than buried in a template literal.
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-1427 — Improper Neutralization of Input Used in AI/ML Prompt Injection
- owasp-llm:2025 · LLM01 — Prompt Injection
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ai-prompt-injection·automated