Skip to content

Commit 22f1461

Browse files
committed
Don't allow __proto__ property to be used for schema default/coerce, fixes #84
1 parent c52a27c commit 22f1461

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
node_modules
2+
yarn.lock
3+
.vscode

lib/validate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ var validate = exports._validate = function(/*Any*/instance,/*Object*/schema,/*O
207207
}
208208

209209
for(var i in objTypeDef){
210-
if(objTypeDef.hasOwnProperty(i)){
210+
if(objTypeDef.hasOwnProperty(i) && i != '__proto__'){
211211
var value = instance[i];
212212
// skip _not_ specified properties
213213
if (value === undefined && options.existingOnly) continue;

test/tests.js

+26
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,30 @@ var suite = vows.describe('JSON Schema').addBatch({
9292
'Json-Ref self-validates': assertSelfValidates('json-ref'),
9393
'Json-Ref/Hyper': assertValidates('json-ref', 'hyper-schema'),
9494
'Json-Ref/Core': assertValidates('json-ref', 'schema')*/
95+
prototypePollution: function() {
96+
console.log('testing')
97+
const instance = JSON.parse(`
98+
{
99+
"$schema":{
100+
"type": "object",
101+
"properties":{
102+
"__proto__": {
103+
"type": "object",
104+
105+
"properties":{
106+
"polluted": {
107+
"type": "string",
108+
"default": "polluted"
109+
}
110+
}
111+
}
112+
},
113+
"__proto__": {}
114+
}
115+
}`);
116+
117+
const a = {};
118+
validate(instance);
119+
assert.equal(a.polluted, undefined);
120+
}
95121
}).export(module);

0 commit comments

Comments
 (0)