Skip to content

Commit

Permalink
Protect from prototype posioning during object coercion
Browse files Browse the repository at this point in the history
  • Loading branch information
devinivy committed Feb 13, 2021
1 parent 1a39334 commit ab56ebe
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Load modules

const Hoek = require('@hapi/hoek');
const Bourne = require('@hapi/bourne');
const Schema = require('./schema');

// Declare internals
Expand Down Expand Up @@ -267,7 +268,7 @@ internals.coerce = function (value, type, options) {
break;
case 'object':
try {
result = JSON.parse(value);
result = Bourne.parse(value);
}
catch (e) {
result = undefined;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
],
"dependencies": {
"@hapi/hoek": "9.x.x",
"@hapi/bourne": "2.x.x",
"alce": "1.x.x",
"joi": "17.x.x",
"yargs": "16.x.x"
Expand Down
1 change: 1 addition & 0 deletions test/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ describe('get()', () => {
get('/coerceObject1', { a: 'b' }, {}, []);
get('/coerceObject1', { b: 'a' }, { obj: '{"b":"a"}' }, []);
get('/coerceObject1', { a: 'b' }, { obj: 'BROKEN JSON' }, []);
get('/coerceObject1', { a: 'b' }, { obj: '{"b":"a","__proto__":"x"}' }, []);

it('fails on invalid key', () => {

Expand Down

0 comments on commit ab56ebe

Please sign in to comment.