Summary
Sanic versions with the affected HTTP/1.1 response pipeline do not reject carriage-return or line-feed characters in serialized response header names and values. If attacker-controlled data reaches response headers, filenames, or cookie attributes, an attacker may inject headers or split responses, potentially enabling session fixation, cache poisoning, or security-header corruption.
Affected context
The vulnerability occurs in Sanic applications that serialize attacker-influenced data into HTTP/1.1 responses without filtering carriage-return and line-feed characters. Risk is higher when applications derive response headers, download filenames, cookie paths, or cookie domains from request data or other untrusted sources, particularly when responses pass through caches, reverse proxies, or browsers that interpret injected headers.
Exploit preconditions
- Attack surface: An HTTP/1.1 response generated by a Sanic application
- Required access: Ability to influence data assigned to response headers, file download filenames, or cookie path and domain attributes
- Trigger point: Serialization of the affected response metadata before it is sent to the client
- Why exploitation is possible: Carriage-return and line-feed characters are not rejected before header names and values are emitted, allowing response metadata to be interpreted as additional headers or separate response content
Why this happens
The underlying bug is insufficient validation of data at an HTTP response serialization boundary. Response header names and values are treated as ordinary strings even when they contain control characters that have structural meaning in the HTTP protocol. This behavior maps to CWE-113: Improper Neutralization of CRLF Sequences in HTTP Headers, because untrusted input can alter the intended response structure.
Potential impact
- An attacker may inject additional HTTP response headers
- Session cookies could be manipulated, potentially enabling session fixation
- Shared caches could be poisoned or supplied with unintended metadata
- Security-related headers could be overwritten, removed, or corrupted
- Clients, proxies, or downstream services could interpret a response differently from the application
General mitigation guidance
Mitigation generally focuses on enforcing protocol-safe output handling and reducing trust in data used to construct responses.
Common defensive patterns include:
- Rejecting or safely normalizing carriage-return and line-feed characters in header names and values
- Using framework and library APIs that enforce HTTP header grammar by default
- Keeping attacker-controlled data out of response metadata where possible
- Applying allowlists for filenames and cookie attribute values
- Separating untrusted data from security-sensitive headers and cookie settings
- Running applications and reverse proxies with consistent header-validation policies
- Limiting cookie scope and privileges so that a single response-injection issue has less impact
How teams detect issues like this
Organizations can identify this class of issue through:
- Static analysis rules that flag response headers, filenames, or cookie attributes populated from request-controlled data
- Code review checks for direct concatenation or interpolation into HTTP response metadata
- Tests that verify control characters are rejected or safely handled at response boundaries
- Integration testing through relevant reverse proxies, caches, and clients
- Runtime policy enforcement that blocks malformed response headers and records rejected control characters
- Automated security review tools that recognize CRLF flow from input sources to HTTP output sinks

