Skip to content

Commit 15231aa

Browse files
bnoordhuisMylesBorins
authored andcommitted
http: reject control characters in http.request()
Unsanitized paths containing line feed characters can be used for header injection and request splitting so reject them with an exception. There seems to be no reasonable use case for allowing control characters (characters <= 31) while there are several scenarios where they can be used to exploit software bugs so reject control characters altogether. PR-URL: #8923 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: not-an-aardvark <not-an-aardvark@users.noreply.github.com>
1 parent 4ce9bfb commit 15231aa

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

lib/_http_client.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function ClientRequest(options, cb) {
4040
if (self.agent && self.agent.protocol)
4141
expectedProtocol = self.agent.protocol;
4242

43-
if (options.path && / /.test(options.path)) {
43+
if (options.path && /[\u0000-\u0020]/.test(options.path)) {
4444
// The actual regex is more like /[^A-Za-z0-9\-._~!$&'()*+,;=/:@]/
4545
// with an additional rule for ignoring percentage-escaped characters
4646
// but that's a) hard to capture in a regular expression that performs
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
4-
var http = require('http');
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const http = require('http');
55

6-
assert.throws(function() {
7-
// Path with spaces in it should throw.
8-
http.get({ path: 'bad path' }, common.fail);
9-
}, /contains unescaped characters/);
6+
function* bad() {
7+
for (let i = 0; i <= 32; i += 1)
8+
yield 'bad' + String.fromCharCode(i) + 'path';
9+
}
10+
11+
for (const path of bad()) {
12+
assert.throws(() => http.get({ path }, common.fail),
13+
/contains unescaped characters/);
14+
}

0 commit comments

Comments
 (0)