Skip to content

Commit 576038f

Browse files
mcollinarvagg
authored andcommittedNov 27, 2018
http: add --security-revert for CVE-2018-12116
PR-URL: nodejs-private/node-private#146 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 513e974 commit 576038f

File tree

2 files changed

+44
-3
lines changed

2 files changed

+44
-3
lines changed
 

‎lib/_http_client.js

+42-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,36 @@ const { outHeadersKey, ondrain } = require('internal/http');
4141
const { nextTick } = require('internal/process/next_tick');
4242
const is_reused_symbol = require('internal/freelist').symbols.is_reused_symbol;
4343

44+
const REVERT_CVE_2018_12116 = process.REVERT_CVE_2018_12116;
45+
46+
// DO NOT USE: this is insecure. See CVE-2018-12116.
47+
// The actual list of disallowed characters in regexp form is more like:
48+
// /[^A-Za-z0-9\-._~!$&'()*+,;=/:@]/
49+
// with an additional rule for ignoring percentage-escaped characters, but
50+
// that's a) hard to capture in a regular expression that performs well, and
51+
// b) possibly too restrictive for real-world usage. So instead we restrict the
52+
// filter to just control characters and spaces.
53+
//
54+
// This function is used in the case of small paths, where manual character code
55+
// checks can greatly outperform the equivalent regexp (tested in V8 5.4).
56+
function isInvalidPath(s) {
57+
var i = 0;
58+
if (s.charCodeAt(0) <= 32) return true;
59+
if (++i >= s.length) return false;
60+
if (s.charCodeAt(1) <= 32) return true;
61+
if (++i >= s.length) return false;
62+
if (s.charCodeAt(2) <= 32) return true;
63+
if (++i >= s.length) return false;
64+
if (s.charCodeAt(3) <= 32) return true;
65+
if (++i >= s.length) return false;
66+
if (s.charCodeAt(4) <= 32) return true;
67+
if (++i >= s.length) return false;
68+
if (s.charCodeAt(5) <= 32) return true;
69+
++i;
70+
for (; i < s.length; ++i)
71+
if (s.charCodeAt(i) <= 32) return true;
72+
return false;
73+
}
4474
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/;
4575

4676
function validateHost(host, name) {
@@ -92,7 +122,18 @@ function ClientRequest(options, cb) {
92122
var path;
93123
if (options.path) {
94124
path = String(options.path);
95-
if (INVALID_PATH_REGEX.test(path))
125+
var invalidPath;
126+
if (REVERT_CVE_2018_12116) {
Has a conversation. Original line has a conversation.
127+
if (path.length <= 39) { // Determined experimentally in V8 5.4
128+
invalidPath = isInvalidPath(path);
129+
} else {
130+
invalidPath = /[\u0000-\u0020]/.test(path);
131+
}
132+
} else {
133+
invalidPath = INVALID_PATH_REGEX.test(path);
134+
}
135+
136+
if (invalidPath)
96137
throw new TypeError('Request path contains unescaped characters');
97138
}
98139

‎src/node_revert.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
**/
1616
namespace node {
1717

18-
#define SECURITY_REVERSIONS(XX)
19-
// XX(CVE_2016_PEND, "CVE-2016-PEND", "Vulnerability Title")
18+
#define SECURITY_REVERSIONS(XX) \
19+
XX(CVE_2018_12116, "CVE-2018-12116", "HTTP request splitting")
2020

2121
enum reversion {
2222
#define V(code, ...) SECURITY_REVERT_##code,

0 commit comments

Comments
 (0)
Please sign in to comment.