Skip to content

Commit f8fdcd4

Browse files
committed
[security] Fix DoS vulnerability
Ignore extension and parameter names that are property names of `Object.prototype` when parsing the `Sec-WebSocket-Extensions` header.
1 parent f7cfc51 commit f8fdcd4

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

lib/Extensions.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ function parse(value) {
2020
value.split(',').forEach(function(v) {
2121
var params = v.split(';');
2222
var token = params.shift().trim();
23-
var paramsList = extensions[token] = extensions[token] || [];
23+
24+
if (extensions[token] === undefined) {
25+
extensions[token] = [];
26+
} else if (!extensions.hasOwnProperty(token)) {
27+
return;
28+
}
29+
2430
var parsedParams = {};
2531

2632
params.forEach(function(param) {
@@ -38,10 +44,15 @@ function parse(value) {
3844
value = value.slice(0, value.length - 1);
3945
}
4046
}
41-
(parsedParams[key] = parsedParams[key] || []).push(value);
47+
48+
if (parsedParams[key] === undefined) {
49+
parsedParams[key] = [value];
50+
} else if (parsedParams.hasOwnProperty(key)) {
51+
parsedParams[key].push(value);
52+
}
4253
});
4354

44-
paramsList.push(parsedParams);
55+
extensions[token].push(parsedParams);
4556
});
4657

4758
return extensions;

test/Extensions.test.js

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ describe('Extensions', function() {
2929
foo: [{ bar: ['hi'] }]
3030
});
3131
});
32+
33+
it('ignores names that match Object.prototype properties', function () {
34+
Extensions.parse('hasOwnProperty, toString').should.eql({});
35+
Extensions.parse('foo; constructor').should.eql({ foo: [{}] });
36+
});
3237
});
3338

3439
describe('format', function() {

0 commit comments

Comments
 (0)