Summary
cpp-httplib's server implementation applies percent-decoding to most header values only after performing validity checks, allowing encoded CRLF sequences (%0D%0A) to bypass field validation.
An attacker who can supply crafted HTTP headers may inject raw CRLF bytes into stored header values, enabling HTTP response splitting and header injection in applications built on cpp-httplib.
Affected context
This vulnerability affects applications using cpp-httplib's server component to accept and process HTTP requests, where:
- User-controlled input is copied into HTTP headers in responses or proxied downstream
- The server relies on cpp-httplib's internal header validation for safety
- Headers (other than Location and Referer) undergo percent-decoding after validation
In such setups, an attacker-controlled request header that includes encoded CRLF sequences can be stored and later reflected or reused by the application.
Exploit preconditions
- Attack surface: HTTP(S) server endpoints implemented with cpp-httplib.
- Required access: Ability to send crafted HTTP requests, including custom headers, to the server (typically unauthenticated network access).
- Trigger point: The server's request parsing logic percent-decodes header values after running
is_field_valuevalidation, allowing%0D%0Ato become\r\nwithin stored header values. - Why exploitation is possible: Validation is performed on the encoded representation, not the decoded content, so CRLF injection is not detected and can be propagated into HTTP responses or downstream requests, leading to response splitting or header injection.
Why this happens
The underlying bug is a classic input canonicalization and validation ordering problem mapped to CWE-93: Improper Neutralization of CRLF Sequences ('CRLF Injection').
cpp-httplib validates header values using is_field_value on the raw, percent-encoded string, then percent-decodes it afterward for most headers. Because %0D%0A passes validation yet decodes into \r\n, untrusted header values can contain embedded line breaks.
This creates a condition where user-controlled input can terminate or extend HTTP headers, aligning with HTTP response splitting and related header injection behaviors (also associated with CWE-444 for improper handling of HTTP requests).
Potential impact
- Attackers may inject additional HTTP response headers by breaking the header section with injected CRLF sequences.
- Attackers could perform HTTP response splitting, causing the server to emit multiple responses for a single request.
- Malicious responses may enable cache poisoning in upstream or downstream HTTP caches.
- Users can be redirected to attacker-controlled content or served manipulated pages, enabling phishing or content spoofing.
- Security controls that rely on header integrity, such as CSP or secure cookie flags, can be weakened or bypassed.
General mitigation guidance
Effective mitigation revolves around robust canonicalization and strict CRLF handling in header processing:
- Normalize or decode request data before validation so checks run on the canonical form of header values.
- Enforce strict rejection of any header value that contains or decodes to control characters like
\ror\n. - Apply a whitelist-based policy for headers derived from user input, limiting allowed characters and length.
- Isolate user-controlled data to header-safe contexts or move user input into the body rather than headers.
- Implement defense-in-depth by treating all header-derived data as untrusted and re-validating before reusing it in outbound responses or proxied requests.
How teams detect issues like this
Organizations can identify this kind of vulnerability through:
- Static analysis: Rules that flag percent-decoding or similar canonicalization happening after validation or sanitization, especially for HTTP header fields.
- Code review: Looking for patterns where user-controlled header values are stored and reused, or where CRLF characters are not explicitly excluded in header-handling code.
- Dynamic testing: Fuzzing HTTP endpoints with encoded CRLF sequences (e.g.,
%0D%0A) in headers and observing whether extra headers or split responses are produced. - Policy enforcement: Introducing coding guidelines that mandate validation on canonicalized inputs and prohibit direct propagation of unverified header values.

