Skip to content

Commit

Permalink
Merge pull request from GHSA-f772-66g8-q5h3
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelGSS authored and metcoder95 committed Dec 26, 2022
1 parent 7a47c2d commit 7ba7486
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/core/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
32 changes: 32 additions & 0 deletions test/request-crlf.js
Original file line number Diff line number Diff line change
@@ -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')
}
})
})

0 comments on commit 7ba7486

Please sign in to comment.