CRLF Injection in Nodejs ‘undici’ via Content-Type
Description
undici is an HTTP/1.1 client, written from scratch for Node.js.=< 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. Example: `` import { request } from 'undici' 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: 1) http://localhost:3000/ 2) http://localhost:3000/foo2` This issue was patched in Undici v5.8.1. Sanitize input when sending content-type headers using user input as a workaround.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
undicinpm | < 5.8.2 | 5.8.2 |
Affected products
1Patches
166165d604fd0Merge pull request from GHSA-f772-66g8-q5h3
2 files changed · +34 −1
lib/core/request.js+2 −1 modified@@ -297,7 +297,8 @@ function processHeader (request, key, val) { } else if ( request.contentType === null && key.length === 12 && - key.toLowerCase() === 'content-type' + key.toLowerCase() === 'content-type' && + headerCharRegex.exec(val) === null ) { request.contentType = val request.headers += `${key}: ${val}\r\n`
test/request-crlf.js+32 −0 added@@ -0,0 +1,32 @@ +'use strict' + +const { createServer } = require('http') +const { test } = require('tap') +const { request, errors } = require('..') + +test('should validate content-type CRLF Injection', (t) => { + t.plan(2) + + const server = createServer((req, res) => { + t.fail('should not receive any request') + res.statusCode = 200 + res.end('hello') + }) + + t.teardown(server.close.bind(server)) + + server.listen(0, async () => { + try { + await request(`http://localhost:${server.address().port}`, { + method: 'GET', + headers: { + 'content-type': 'application/json\r\n\r\nGET /foo2 HTTP/1.1' + }, + }) + t.fail('request should fail') + } catch (e) { + t.type(e, errors.InvalidArgumentError) + t.equal(e.message, 'invalid content-type header') + } + }) +})
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
5- github.com/advisories/GHSA-f772-66g8-q5h3ghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2022-35948ghsaADVISORY
- github.com/nodejs/undici/commit/66165d604fd0aee70a93ed5c44ad4cc2df395f80ghsaWEB
- github.com/nodejs/undici/releases/tag/v5.8.2ghsaWEB
- github.com/nodejs/undici/security/advisories/GHSA-f772-66g8-q5h3ghsaWEB
News mentions
0No linked articles in our index yet.