Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

[Fix] setLocale: do not allow prototype pollution #2

Merged
merged 2 commits into from
Oct 28, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-size-snapshot": "^0.12.0",
"sinon": "^9.2.0",
"sinon-chai": "^3.5.0"
"sinon-chai": "^3.5.0",
"synchronous-promise": "^2.0.15"
},
"dependencies": {
"@babel/runtime": "^7.10.5",
Expand Down
4 changes: 2 additions & 2 deletions src/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ export let array = {
max: '${path} field must have less than or equal to ${max} items',
};

export default {
export default Object.assign(Object.create(null), {
mixed,
string,
number,
date,
object,
array,
boolean,
};
});
2 changes: 1 addition & 1 deletion test/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ describe('Object types', () => {
err.message.should.match(/must be a `string` type/);
});

it.only('should respect child schema with strict()', async () => {
it('should respect child schema with strict()', async () => {
inst = object({
field: number().strict(),
});
Expand Down
16 changes: 16 additions & 0 deletions test/setLocale.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,20 @@ describe('Custom locale', () => {
const locale = require('../src/locale').default;
expect(locale.string.email).to.equal('Invalid email');
});

it('should not allow prototype pollution', () => {
const payload = JSON.parse('{"__proto__":{"polluted":"Yes! Its Polluted"}}');

expect(() => setLocale(payload)).to.throw();

expect(payload).not.to.have.property('polluted');
});

it('should not pollute Object.prototype builtins', () => {
const payload = { toString: { polluted: 'oh no' } };

expect(() => setLocale(payload)).to.throw();

expect(Object.prototype.toString).not.to.have.property('polluted');
});
});