Skip to content

Commit 15d6bdb

Browse files
authored
Merge pull request #367 from saulotoledo/fix-prototype-pollution-vulnerability
Fix prototype pollution vulnerabilities
2 parents 94db7dc + 8f04eb9 commit 15d6bdb

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/TransformOperationExecutor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ export class TransformOperationExecutor {
145145

146146
// traverse over keys
147147
for (const key of keys) {
148+
if (key === '__proto__' || key === 'constructor') {
149+
continue;
150+
}
151+
148152
const valueKey = key;
149153
let newValueKey = key, propertyName = key;
150154
if (!this.options.ignoreDecorators && targetType) {

test/functional/basic-functionality.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,20 @@ describe("basic functionality", () => {
17491749
expect(transformedClass).toBeInstanceOf(TestClass);
17501750
});
17511751

1752+
it('should not pollute the prototype with a `__proto__` property',() => {
1753+
const object = JSON.parse('{"__proto__": { "admin": true }}');
1754+
const plainObject = {};
1755+
classToPlainFromExist(object, plainObject);
1756+
expect((plainObject as any).admin).toEqual(undefined);
1757+
});
1758+
1759+
it('should not pollute the prototype with a `constructor.prototype` property', () => {
1760+
const object = JSON.parse('{"constructor": { "prototype": { "admin": true }}}');
1761+
const plainObject = {};
1762+
classToPlainFromExist(object, plainObject);
1763+
expect((plainObject as any).admin).toEqual(undefined);
1764+
});
1765+
17521766
it("should default union types where the plain type is an array to an array result", () => {
17531767
class User {
17541768
name: string;

0 commit comments

Comments
 (0)