Skip to content

Commit b7b8b27

Browse files
authored
Fix for CVE-2021-23450, prototype pollution (#418)
1 parent b51dc65 commit b7b8b27

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

_base/lang.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ define(["./kernel", "../has", "../sniff"], function(dojo, has){
3131
try{
3232
for(var i = 0; i < parts.length; i++){
3333
var p = parts[i];
34+
// Fix for prototype pollution CVE-2021-23450
35+
if (p === '__proto__' || p === 'constructor') {
36+
return;
37+
}
3438
if(!(p in context)){
3539
if(create){
3640
context[p] = {};

tests/unit/_base/lang.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,20 @@ define([
6262

6363
lang.setObject('foo', { bar: 'test' }, test);
6464
assert.deepEqual(test, { foo: { bar: 'test' } });
65+
66+
// CVE-2021-23450 tests
67+
// Test that you can't set fields on Object.prototype itself.
68+
const obj = {};
69+
lang.setObject("__proto__.vuln", "polluted!", obj);
70+
assert.isUndefined("anything".vuln);
71+
72+
// Test that you can't set fields on Object.constructor itself.
73+
lang.setObject("constructor.vuln", "polluted!", obj);
74+
assert.isUndefined("anything".constructor.vuln);
75+
76+
// Test that you can still set normal fields in an obj.
77+
lang.setObject("foo.bar", "value for normal field", obj);
78+
assert.strictEqual(obj.foo.bar, "value for normal field");
6579
},
6680

6781
'.mixin': function () {

0 commit comments

Comments
 (0)