Summary
Serendipity's email sending logic inserts the raw HTTP Host header into the Message-ID SMTP header without proper validation or sanitization.
If an attacker can control the Host header during an email-triggering action, they can inject arbitrary SMTP headers into outgoing emails, enabling identity spoofing and manipulation of email threading and reputation.
Affected context
The vulnerability arises in Serendipity installations (versions 2.6-beta2 and below) when the application sends emails, such as comment notifications or subscription messages.
During email generation, the value of $_SERVER['HTTP_HOST'] is embedded directly into the Message-ID SMTP header without invoking the existing serendipity_isResponseClean() sanitization routine.
Deployments where upstream components, proxies, or clients can influence the Host header are particularly exposed.
Exploit preconditions
- Attack surface: HTTP interface of the Serendipity blog where email-triggering actions occur (e.g., comment posting, subscription workflows).
- Required access: Ability to send HTTP requests to the blog and control or override the
Hostheader (often achievable by a remote unauthenticated attacker unless constrained by infrastructure). - Trigger point: Any code path that sends an email and constructs a
Message-IDheader using$_SERVER['HTTP_HOST']ininclude/functions.inc.php. - Why exploitation is possible: The Host header is treated as trusted input and inserted into the
Message-IDSMTP header without validation or cleansing, allowing newline or crafted content to break out of the intended header value and introduce additional SMTP headers.
Why this happens
The root cause is improper neutralization of user-controllable input when constructing SMTP headers, aligning with CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting'), generalized here as header injection.
The application directly uses $_SERVER['HTTP_HOST'] in the Message-ID header, assuming it to be trustworthy, and fails to apply the existing serendipity_isResponseClean() sanitization routine.
Because SMTP and HTTP headers share similar line-based semantics, unvalidated inclusion of header content enables attackers to inject additional headers or manipulate existing ones.
Conceptually, this is an input validation and output encoding failure: untrusted request metadata is embedded into protocol-level headers without filtering control characters or enforcing a strict, safe format.
Potential impact
- Email identity spoofing by manipulating header fields associated with the blog or sender domain.
- Reply or conversation hijacking via crafted
Message-IDvalues that influence threading in email clients. - Abuse of the blog's email reputation by embedding attacker-controlled domains or headers into legitimate emails.
- Facilitation of phishing or social engineering by making malicious emails appear associated with a trusted blog.
- Potential interference with downstream mail handling, logging, or filtering due to malformed or injected headers.
General mitigation guidance
Effective mitigation focuses on treating all request-derived metadata, including Host, as untrusted and constraining its use in protocol headers.
Recommended defensive patterns include:
- Validating the
Hostvalue against a strict whitelist or configuration-derived canonical domain before using it in any header. - Applying a central sanitization function to all header-bound values that strips or rejects control characters, CR/LF sequences, and other unsafe characters.
- Constructing
Message-IDand similar headers from server-side constants or configuration (e.g., application domain) rather than from client-controlled request data. - Encapsulating email header assembly behind a dedicated utility that enforces safe formatting and refuses untrusted input that does not match an expected pattern (such as a simple hostname).
- Deploying the application with web server and reverse proxy configurations that normalize or restrict the
Hostheader to known values wherever feasible, reducing the attack surface if application-level checks fail.
How teams detect issues like this
Detection typically involves a combination of code-level inspection and runtime monitoring:
- Static analysis: Create rules to flag any direct use of
$_SERVER['HTTP_HOST'], other$_SERVERentries, or user input when concatenated into mail headers, HTTP headers, or other protocol metadata without sanitization. - Code review signals: During review, treat all header construction code as security-sensitive and verify that a single, well-tested sanitization function is applied consistently. Watch for string concatenation into headers and for bypasses of existing validation utilities.
- Policy enforcement: Introduce coding guidelines that prohibit direct embedding of request data in headers and require using safe wrappers for email and HTTP response construction.
- Automated tooling: Configure linters or security scanners to detect potential header injection patterns, such as unescaped
\r/\nor uncontrolled domain values in header fields, and integrate these checks into CI pipelines.

