Skip to content

Commit e58e918

Browse files
committedJul 28, 2019
Take 2
1 parent 9d3ce5f commit e58e918

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed
 

‎querystring/parse.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ module.exports = function(string) {
1919
for (var j = 0; j < levels.length; j++) {
2020
var level = levels[j], nextLevel = levels[j + 1]
2121
var isNumber = nextLevel == "" || !isNaN(parseInt(nextLevel, 10))
22-
var isValue = j === levels.length - 1
2322
if (level === "") {
2423
var key = levels.slice(0, j).join()
2524
if (counters[key] == null) {
@@ -29,15 +28,15 @@ module.exports = function(string) {
2928
}
3029
// Disallow direct prototype pollution
3130
else if (level === "__proto__") break
32-
if (isValue) cursor[level] = value
31+
if (j === levels.length - 1) cursor[level] = value
3332
else {
3433
// Read own properties exclusively to disallow indirect
3534
// prototype pollution
36-
value = Object.getOwnPropertyDescriptor(cursor, level)
37-
if (value != null) value = value.value
38-
if (value == null) value = cursor[level] = isNumber ? [] : {}
35+
var desc = Object.getOwnPropertyDescriptor(cursor, level)
36+
if (desc != null) desc = desc.value
37+
if (desc == null) cursor[level] = desc = isNumber ? [] : {}
38+
cursor = desc
3939
}
40-
cursor = value
4140
}
4241
}
4342
return data

‎querystring/tests/test-parseQueryString.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,11 @@ o.spec("parseQueryString", function() {
105105
})
106106
o("doesn't pollute prototype indirectly, retains `constructor`", function() {
107107
var prev = Object.prototype.toString
108-
var data = parseQueryString("constructor%5Bprototype%5D%5BtoString%5D=123")
108+
var data = parseQueryString("a=b&constructor%5Bprototype%5D%5BtoString%5D=123")
109109
o(Object.prototype.toString).equals(prev)
110-
o(data).deepEquals({a: "b"})
110+
// The deep matcher is borked here.
111+
o(Object.keys(data)).deepEquals(["a", "constructor"])
112+
o(data.a).equals("b")
113+
o(data.constructor).deepEquals({prototype: {toString: "123"}})
111114
})
112115
})

0 commit comments

Comments
 (0)
Please sign in to comment.