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

CVE 2021 25943 fix2 #162

Closed
wants to merge 2 commits into from
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "101",
"version": "1.6.3",
"version": "1.6.4",
"description": "common javascript utils that can be required selectively that assume es5+",
"main": "index.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions set.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ var keypather = require('keypather')();
module.exports = set;

function set (obj, key, val) {
if (key === '__proto__' || key === 'prototype' || key === 'constructor') {
return
}
var setObj;
if (arguments.length === 1) {
// (setObj)
Expand Down
1 change: 0 additions & 1 deletion test/test-put.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ describe('put', function () {

describe('keypaths', function () {
it('should put via keypath object', function (done) {
console.log('hello')
var obj = {
foo: {
bar: 1
Expand Down
21 changes: 21 additions & 0 deletions test/test-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,27 @@ describe('set', function () {
expect(err).to.exist();
done();
}
});
it('should do nothing when when using __proto__ reserved key', function (done) {
target = {}
saved = target.__proto__
set(target, "__proto__", null);
expect(target.__proto__).to.equal(saved);
done();
});
it('should do nothing when using prototype reserved key', function (done) {
target = {}
saved = target.prototype
set(target, "prototype", null);
expect(target.prototype).to.equal(saved);
done()
});
it('should do nothing when using constructor reserved key', function (done) {
target = {}
saved = target.constructor
set(target, "constructor", null);
expect(target.constructor).to.equal(saved);
done()
});
});
});