Merge fields sanitized to prevent header injection
Why it matters
Email header injection exploits the CRLF-based structure of the SMTP protocol. An attacker who can control a merge field value — say, a user's first name registered as Alice\r\nBcc: victim@example.com — can inject additional headers into outgoing emails, silently copying sends to arbitrary recipients. This maps to CWE-93 (CRLF injection) and OWASP A03 (Injection). Subject lines and Reply-To addresses built from unsanitized user input are the most common injection surfaces. The Compliance & Consent Engine category verifies that unsubscribe mechanisms exist — header injection is the vector by which those mechanisms can be bypassed.
Severity rationale
Critical because CRLF injection in email headers allows an attacker to redirect outbound email to unintended recipients without any access control bypass.
Remediation
Strip CR, LF, and null bytes from all user-controlled values placed in headers, and enforce a length cap, in lib/email/sanitize.ts:
export function sanitizeHeader(value: string): string {
return value.replace(/[\r\n\0]/g, ' ').trim().slice(0, 256)
}
export function sanitizeEmailAddress(address: string): string {
const clean = address.replace(/[\r\n\0<>]/g, '').trim()
if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(clean)) {
throw new Error(`Invalid email address: ${clean}`)
}
return clean
}
Apply sanitizeHeader to every field that accepts user input before the value is passed to the ESP SDK — at minimum: subject, from name, and reply-to address.
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 Sending Pipeline & Infrastructure Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-93 — Improper Neutralization of CRLF Sequences (Email Header Injection)
- owasp:2021 · A03 — Injection
Taxons
History
- 2026-04-18·v1.0.0·Initial import from sending-pipeline-infrastructure·automated