Skip to content

Commit 66165d6

Browse files
authored
Merge pull request from GHSA-f772-66g8-q5h3
1 parent 124f7eb commit 66165d6

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/core/request.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ function processHeader (request, key, val) {
297297
} else if (
298298
request.contentType === null &&
299299
key.length === 12 &&
300-
key.toLowerCase() === 'content-type'
300+
key.toLowerCase() === 'content-type' &&
301+
headerCharRegex.exec(val) === null
301302
) {
302303
request.contentType = val
303304
request.headers += `${key}: ${val}\r\n`

test/request-crlf.js

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
'use strict'
2+
3+
const { createServer } = require('http')
4+
const { test } = require('tap')
5+
const { request, errors } = require('..')
6+
7+
test('should validate content-type CRLF Injection', (t) => {
8+
t.plan(2)
9+
10+
const server = createServer((req, res) => {
11+
t.fail('should not receive any request')
12+
res.statusCode = 200
13+
res.end('hello')
14+
})
15+
16+
t.teardown(server.close.bind(server))
17+
18+
server.listen(0, async () => {
19+
try {
20+
await request(`http://localhost:${server.address().port}`, {
21+
method: 'GET',
22+
headers: {
23+
'content-type': 'application/json\r\n\r\nGET /foo2 HTTP/1.1'
24+
},
25+
})
26+
t.fail('request should fail')
27+
} catch (e) {
28+
t.type(e, errors.InvalidArgumentError)
29+
t.equal(e.message, 'invalid content-type header')
30+
}
31+
})
32+
})

0 commit comments

Comments
 (0)