Skip to content

Commit

Permalink
fix(extend): remove prototype pollution (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbanksdesign authored Mar 6, 2021
1 parent 9b5cfad commit b99710a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions __tests__/extend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,13 @@ describe('extend', () => {
expect(StyleDictionary3.foo).toBe('boo');
expect(StyleDictionary).not.toHaveProperty('foo');
});

it(`should not pollute the prototype`, () => {
const obj = {};
let opts = JSON.parse('{"__proto__":{"polluted":"yes"}}');
console.log("Before : " + obj.polluted);
StyleDictionary.extend(opts);
console.log("After : " + obj.polluted);
expect(obj.polluted).toBeUndefined();
});
});
2 changes: 2 additions & 0 deletions lib/utils/deepExtend.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ function deepExtend(objects, collision, path) {
for (name in options) {
if (!options.hasOwnProperty(name))
continue;
if (name === '__proto__')
continue;

src = target[name];
copy = options[name];
Expand Down

0 comments on commit b99710a

Please sign in to comment.