Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prototype pollution #114 #118

Merged
merged 2 commits into from Mar 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/parse.js
Expand Up @@ -153,6 +153,12 @@ function parsePlistXML (node) {
if (isEmptyNode(node)) {
return '';
}

invariant(
node.childNodes[0].nodeValue !== '__proto__',
'__proto__ keys can lead to prototype pollution. More details on CVE-2022-22912'
);

return node.childNodes[0].nodeValue;
} else if (node.nodeName === 'string') {
res = '';
Expand Down
12 changes: 12 additions & 0 deletions test/parse.js
Expand Up @@ -187,6 +187,18 @@ U=</data>
);
assert.deepEqual(parsed, { a: { a1: true } });
});

/* Test to protect against CVE-2022-22912 */
it('should throw if key value is __proto__', function () {
assert.throws(function () {
parseFixture('<dict><key>__proto__</key><dict><key>length</key><string>polluted</string></dict></dict>');
});

// adding backslash should still be protected.
assert.throws(function () {
parseFixture('<dict><key>_\_proto_\_</key><dict><key>length</key><string>polluted</string></dict></dict>');
});
});
});

describe('integration', function () {
Expand Down