Skip to content

Commit a2eff05

Browse files
authored
Merge pull request from GHSA-5r9g-qh6m-jxff
1 parent f5c89e5 commit a2eff05

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/core/request.js

+3
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ function processHeader (request, key, val) {
304304
key.length === 4 &&
305305
key.toLowerCase() === 'host'
306306
) {
307+
if (headerCharRegex.exec(val) !== null) {
308+
throw new InvalidArgumentError(`invalid ${key} header`)
309+
}
307310
// Consumed by Client
308311
request.host = val
309312
} else if (

test/headers-crlf.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict'
2+
3+
const { test } = require('tap')
4+
const { Client } = require('..')
5+
const { createServer } = require('http')
6+
const EE = require('events')
7+
8+
test('CRLF Injection in Nodejs ‘undici’ via host', (t) => {
9+
t.plan(1)
10+
11+
const server = createServer(async (req, res) => {
12+
res.end()
13+
})
14+
t.teardown(server.close.bind(server))
15+
16+
server.listen(0, async () => {
17+
const client = new Client(`http://localhost:${server.address().port}`)
18+
t.teardown(client.close.bind(client))
19+
20+
const unsanitizedContentTypeInput = '12 \r\n\r\naaa:aaa'
21+
22+
try {
23+
const { body } = await client.request({
24+
path: '/',
25+
method: 'POST',
26+
headers: {
27+
'content-type': 'application/json',
28+
'host': unsanitizedContentTypeInput
29+
},
30+
body: 'asd'
31+
})
32+
await body.dump()
33+
} catch (err) {
34+
t.same(err.code, 'UND_ERR_INVALID_ARG')
35+
}
36+
})
37+
})

0 commit comments

Comments
 (0)