Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ function parsePlistXML (node) {
);
new_obj[key] = parsePlistXML(node.childNodes[i]);
}
if ( key === __proto__) {
key = '__proto__';
}
counter += 1;
}
if (counter % 2 === 1) {
Expand Down
22 changes: 22 additions & 0 deletions test/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -499,5 +499,27 @@ int main(int argc, char *argv[])
CFBundleAllowMixedLocalizations: true
});
});
it('fixed Prototype Pollution using .parse() #114', function () {
var xml = multiline(function () {
/*
var xmlPollution = `
<plist version="1.0">
<dict>
<key>__proto__</key>
<dict>
<key>length</key>
<string>polluted</string>
</dict>
</dict>
</plist>`;
*/
});
var parsed = parse(xml);
assert.deepEqual(parsed, {
__proto__: {
length: 'polluted'
}
});
Comment on lines +518 to +522
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deepEqual does not test the objects' prototypes, which is why it passes. A deepStrictEqual test would fail, but we could never make it pass. A better test would check that parsed.length is not provided through the prototype chain.

Suggested change
assert.deepEqual(parsed, {
__proto__: {
length: 'polluted'
}
});
assert.notEqual(parsed.length, 'polluted');

});
});
});