Skip to content

Commit 7273d85

Browse files
committed
fix: encode/decode proto pollution
1 parent 4d9f205 commit 7273d85

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/decode.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ export default function decode(value: any): any {
4949
}
5050
const copy = {};
5151
for (const k in value) {
52-
copy[k] = decode(value[k]);
52+
if (Object.prototype.hasOwnProperty.call(value, k)) {
53+
copy[k] = decode(value[k]);
54+
}
5355
}
5456
return copy;
5557
}

src/encode.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ function encode(
7171
if (value && typeof value === 'object') {
7272
const output = {};
7373
for (const k in value) {
74-
output[k] = encode(value[k], disallowObjects, forcePointers, seen, offline);
74+
// Only iterate over own properties
75+
if (Object.prototype.hasOwnProperty.call(value, k)) {
76+
output[k] = encode(value[k], disallowObjects, forcePointers, seen, offline);
77+
}
7578
}
7679
return output;
7780
}

0 commit comments

Comments
 (0)