CVE-2020-7748 (TypeScript, published 2020-10-20T11:15Z)
Description: value: This affects the package @tsed/core before 5.65.7. This vulnerability relates to the deepExtend function which is used as part of the utils directory. Depending on if user input is provided, an attacker can overwrite and pollute the object prototype of a program.
Severity: MEDIUM (CVSS v3 base score: 8.1)
Weakness: CWE-1321 \u2014 Improperly Controlled Modification of Object Prototype Attributes ('Prototype Pollution')
The product receives input from an upstream component that specifies attributes that are to be initialized or updated in an object, but it does not properly control modifications of attributes of the object prototype.
Repository: https://github.com/TypedProject/tsed
Files changed:
packages/common/src/converters/components/MapConverter.ts
packages/common/src/converters/components/SetConverter.ts
packages/common/src/converters/services/ConverterService.ts
packages/core/src/utils/cleanObject.ts
packages/json-mapper/src/components/MapMapper.ts
packages/json-mapper/src/components/SetMapper.ts
packages/json-mapper/src/utils/deserialize.ts
packages/mongoose/src/utils/createSchema.ts
Commit message: fix: Use objectKeys to prevent prototype pollution


Vulnerable code:
    Object.keys(data).forEach((key) => {
    Object.keys(data).forEach((key) => {
import {getClass, isArrayOrArrayClass, isEmpty, isPrimitiveOrPrimitiveClass, Metadata, Type} from "@tsed/core";
    const keys = properties.size ? Array.from(properties.keys()) : Object.keys(obj);
    Object.keys(obj).forEach((propertyName: string) => {

  return Object.entries(obj).reduce(
    (obj, [key, value]) =>
      value === undefined
        ? obj
        : {
            ...obj,
            [key]: value
          },
    {}
  );
    Object.keys(data).forEach((key) => {
    Object.keys(data).forEach((key) => {
import {isArray, isEmpty, isNil, MetadataTypes, nameOf, Type} from "@tsed/core";
  let keys = Object.keys(src);
export const cleanProps = (src: any) =>
  Object.keys(src).reduce((obj: any, k: any) => {
    if (src[k] !== undefined) {
      obj[k] = src[k];
    }

    return obj;
  }, {});
import {getClass, Store, Type} from "@tsed/core";
import {cleanProps} from "./cleanProps";
  schemaTypeOptions = cleanProps({...schemaTypeOptions, ...rawMongooseSchema});

Fixed code:
import {objectKeys} from "@tsed/core";
    objectKeys(data).forEach((key) => {
import {objectKeys} from "@tsed/core";
    objectKeys(data).forEach((key) => {
import {getClass, isArrayOrArrayClass, isEmpty, isPrimitiveOrPrimitiveClass, Metadata, objectKeys, Type} from "@tsed/core";
    const keys = properties.size ? Array.from(properties.keys()) : objectKeys(obj);
    objectKeys(obj).forEach((propertyName: string) => {
import {isProtectedKey} from "./isProtectedKey";
  return Object.entries(obj).reduce((obj, [key, value]) => {
    if (isProtectedKey(key)) {
      return obj;
    }

    return value === undefined
      ? obj
      : {
          ...obj,
          [key]: value
        };
  }, {});
import {objectKeys} from "@tsed/core";
    objectKeys(data).forEach((key) => {
import {objectKeys} from "@tsed/core";
    objectKeys(data).forEach((key) => {
import {isArray, isEmpty, isNil, MetadataTypes, nameOf, objectKeys, Type} from "@tsed/core";
  let keys = objectKeys(src);
import {cleanObject, getClass, Store, Type} from "@tsed/core";
  schemaTypeOptions = cleanObject({...schemaTypeOptions, ...rawMongooseSchema});