minimist 1.2.3 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +6 -2
- package/package.json +1 -1
- package/readme.markdown +10 -0
- package/test/proto.js +23 -0
package/index.js
CHANGED
|
@@ -70,7 +70,7 @@ module.exports = function (args, opts) {
|
|
|
70
70
|
var o = obj;
|
|
71
71
|
for (var i = 0; i < keys.length-1; i++) {
|
|
72
72
|
var key = keys[i];
|
|
73
|
-
if (key
|
|
73
|
+
if (isConstructorOrProto(o, key)) return;
|
|
74
74
|
if (o[key] === undefined) o[key] = {};
|
|
75
75
|
if (o[key] === Object.prototype || o[key] === Number.prototype
|
|
76
76
|
|| o[key] === String.prototype) o[key] = {};
|
|
@@ -79,7 +79,7 @@ module.exports = function (args, opts) {
|
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
var key = keys[keys.length - 1];
|
|
82
|
-
if (key
|
|
82
|
+
if (isConstructorOrProto(o, key)) return;
|
|
83
83
|
if (o === Object.prototype || o === Number.prototype
|
|
84
84
|
|| o === String.prototype) o = {};
|
|
85
85
|
if (o === Array.prototype) o = [];
|
|
@@ -243,3 +243,7 @@ function isNumber (x) {
|
|
|
243
243
|
return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
|
|
244
244
|
}
|
|
245
245
|
|
|
246
|
+
|
|
247
|
+
function isConstructorOrProto (obj, key) {
|
|
248
|
+
return key === 'constructor' && typeof obj[key] === 'function' || key === '__proto__';
|
|
249
|
+
}
|
package/package.json
CHANGED
package/readme.markdown
CHANGED
|
@@ -29,6 +29,16 @@ $ node example/parse.js -x 3 -y 4 -n5 -abc --beep=boop foo bar baz
|
|
|
29
29
|
beep: 'boop' }
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
# security
|
|
33
|
+
|
|
34
|
+
Previous versions had a prototype pollution bug that could cause privilege
|
|
35
|
+
escalation in some circumstances when handling untrusted user input.
|
|
36
|
+
|
|
37
|
+
Please use version 1.2.6 or later:
|
|
38
|
+
|
|
39
|
+
* https://security.snyk.io/vuln/SNYK-JS-MINIMIST-2429795 (version <=1.2.5)
|
|
40
|
+
* https://snyk.io/vuln/SNYK-JS-MINIMIST-559764 (version <=1.2.3)
|
|
41
|
+
|
|
32
42
|
# methods
|
|
33
43
|
|
|
34
44
|
``` js
|
package/test/proto.js
CHANGED
|
@@ -35,3 +35,26 @@ test('proto pollution (string)', function (t) {
|
|
|
35
35
|
t.equal(argv.x.z, undefined);
|
|
36
36
|
t.end();
|
|
37
37
|
});
|
|
38
|
+
|
|
39
|
+
test('proto pollution (constructor)', function (t) {
|
|
40
|
+
var argv = parse(['--constructor.prototype.y','123']);
|
|
41
|
+
t.equal({}.y, undefined);
|
|
42
|
+
t.equal(argv.y, undefined);
|
|
43
|
+
t.end();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('proto pollution (constructor function)', function (t) {
|
|
47
|
+
var argv = parse(['--_.concat.constructor.prototype.y', '123']);
|
|
48
|
+
function fnToBeTested() {}
|
|
49
|
+
t.equal(fnToBeTested.y, undefined);
|
|
50
|
+
t.equal(argv.y, undefined);
|
|
51
|
+
t.end();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// powered by snyk - https://github.com/backstage/backstage/issues/10343
|
|
55
|
+
test('proto pollution (constructor function) snyk', function (t) {
|
|
56
|
+
var argv = parse('--_.constructor.constructor.prototype.foo bar'.split(' '));
|
|
57
|
+
t.equal((function(){}).foo, undefined);
|
|
58
|
+
t.equal(argv.y, undefined);
|
|
59
|
+
t.end();
|
|
60
|
+
})
|