CVE-2022-35948: CRLF Injection in Nodejs ‘undici’ via Content-Type
The undici library did not properly sanitise the content-type header, allowing CRLF injection when user input was used. An attacker could inject extra HTTP requests, causing the library to perform two requests in a single API call.
- Triaged in 4 hours
- Fixed in 15 days
- Paid in 15 days
- Disclosed after 45 days
Summary by the program
CRLF Injection in Nodejs ‘undici’ via Content-Type
Package: undici (npm) Affected versions: =< 5.8.1 Patched versions: 5.8.2
Impact =< undici @ 5.8.0 users are vulnerable to CRLF Injection on headers when using unsanitized input as request headers, more specifically, inside the content-type header.
Patches This issue was patched in Undici v5.8.1
Workarounds Sanitize input when sending content-type headers using user input.
Full GHSA Link: https://github.com/nodejs/undici/security/advisories/GHSA-f772-66g8-q5h3
The report
undici library should be protects HTTP headers from CRLF injection vulnerabilities. However, CRLF injection exists in the ‘content-type’ header of undici.request api.
Impact
=< [email protected] users are vulnerable to CRLF Injection on headers when using unsanitized input as request headers, more specifically, inside the content-type header.
Example:
const unsanitizedContentTypeInput = 'application/json\r\n\r\nGET /foo2 HTTP/1.1'
await request('http://localhost:3000, {
method: 'GET',
headers: {
'content-type': unsanitizedContentTypeInput
},
})
The above snippet will perform two requests in a single request API call:
http://localhost:3000/ http://localhost:3000/foo2
I have submitted the report: https://hackerone.com/reports/1638888 Advisories: https://github.com/nodejs/undici/security/advisories/GHSA-f772-66g8-q5h3 Resolved as of https://github.com/nodejs/undici/releases/tag/v5.8.2
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the library failed to validate or sanitise the content-type header value, allowing carriage return and line feed characters to be interpreted as header separators.
Impact
An attacker could cause the library to send an extra request to a path of their choosing; the text does not specify further consequences.
What the attacker needed
Application uses undici <=5.8.1; user input passed to content-type header
The fix
The issue was resolved as of undici v5.8.2.
How it was found
- Import the request function from undici.
- Set a content-type header to a value containing CRLF characters followed by a second HTTP request line.
- Call request with that header.
- Observe that two requests are performed instead of one.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
CRLF injection is when an attacker inserts special newline characters into data that is later used in an HTTP header. This can trick the server into treating part of the input as a new request. Here, if a developer passed user input directly as the content-type header, an attacker could make the library send an extra request.
What is Smuggling / CRLF?
A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.