Skip to content

Commit

Permalink
Merge pull request #367 from saulotoledo/fix-prototype-pollution-vuln…
Browse files Browse the repository at this point in the history
…erability

Fix prototype pollution vulnerabilities
  • Loading branch information
jotamorais authored Jul 20, 2020
2 parents 94db7dc + 8f04eb9 commit 15d6bdb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/TransformOperationExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ export class TransformOperationExecutor {

// traverse over keys
for (const key of keys) {
if (key === '__proto__' || key === 'constructor') {
continue;
}

const valueKey = key;
let newValueKey = key, propertyName = key;
if (!this.options.ignoreDecorators && targetType) {
Expand Down
14 changes: 14 additions & 0 deletions test/functional/basic-functionality.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1749,6 +1749,20 @@ describe("basic functionality", () => {
expect(transformedClass).toBeInstanceOf(TestClass);
});

it('should not pollute the prototype with a `__proto__` property',() => {
const object = JSON.parse('{"__proto__": { "admin": true }}');
const plainObject = {};
classToPlainFromExist(object, plainObject);
expect((plainObject as any).admin).toEqual(undefined);
});

it('should not pollute the prototype with a `constructor.prototype` property', () => {
const object = JSON.parse('{"constructor": { "prototype": { "admin": true }}}');
const plainObject = {};
classToPlainFromExist(object, plainObject);
expect((plainObject as any).admin).toEqual(undefined);
});

it("should default union types where the plain type is an array to an array result", () => {
class User {
name: string;
Expand Down

0 comments on commit 15d6bdb

Please sign in to comment.