Skip to content

Commit 0623a47

Browse files
authored
Merge commit from fork
* disallow __proto__ property on object * changeset * changeset
1 parent 02d20e8 commit 0623a47

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

.changeset/huge-ads-study.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'devalue': patch
3+
---
4+
5+
fix: disallow array method access when parsing

.changeset/rich-clouds-walk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'devalue': patch
3+
---
4+
5+
fix: disallow `__proto__` properties on objects

src/parse.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ export function unflatten(parsed, revivers) {
4444
if (index === NEGATIVE_INFINITY) return -Infinity;
4545
if (index === NEGATIVE_ZERO) return -0;
4646

47-
if (standalone) throw new Error(`Invalid input`);
47+
if (standalone || typeof index !== 'number') {
48+
throw new Error(`Invalid input`);
49+
}
4850

4951
if (index in hydrated) return hydrated[index];
5052

@@ -177,6 +179,10 @@ export function unflatten(parsed, revivers) {
177179
hydrated[index] = object;
178180

179181
for (const key in value) {
182+
if (key === '__proto__') {
183+
throw new Error('Cannot parse an object with a `__proto__` property');
184+
}
185+
180186
const n = value[key];
181187
object[key] = hydrate(n);
182188
}

test/test.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,16 @@ const invalid = [
681681
name: 'empty array',
682682
json: '[]',
683683
message: 'Invalid input'
684+
},
685+
{
686+
name: 'prototype pollution',
687+
json: '[{"__proto__":1},{}]',
688+
message: 'Cannot parse an object with a `__proto__` property'
689+
},
690+
{
691+
name: 'bad index',
692+
json: '[{"0":1,"toString":"push"},"hello"]',
693+
message: 'Invalid input'
684694
}
685695
];
686696

0 commit comments

Comments
 (0)