Skip to content

Commit

Permalink
Merge pull request #262 from 418sec/1-npm-fast-json-patch
Browse files Browse the repository at this point in the history
Security Fix for Prototype Pollution - huntr.dev
  • Loading branch information
Starcounter-Jack committed Aug 13, 2021
2 parents 34d6405 + 5edc97d commit 7ad6af4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
6 changes: 4 additions & 2 deletions commonjs/core.js
Expand Up @@ -188,8 +188,10 @@ function applyOperation(document, operation, validateOperation, mutateDocument,
if (key && key.indexOf('~') != -1) {
key = helpers_js_1.unescapePathComponent(key);
}
if (banPrototypeModifications && key == '__proto__') {
throw new TypeError('JSON-Patch: modifying `__proto__` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
if (banPrototypeModifications &&
(key == '__proto__' ||
(key == 'prototype' && t > 0 && keys[t - 1] == 'constructor'))) {
throw new TypeError('JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
}
if (validateOperation) {
if (existingPathFragment === undefined) {
Expand Down
6 changes: 4 additions & 2 deletions module/core.mjs
Expand Up @@ -186,8 +186,10 @@ export function applyOperation(document, operation, validateOperation, mutateDoc
if (key && key.indexOf('~') != -1) {
key = unescapePathComponent(key);
}
if (banPrototypeModifications && key == '__proto__') {
throw new TypeError('JSON-Patch: modifying `__proto__` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
if (banPrototypeModifications &&
(key == '__proto__' ||
(key == 'prototype' && t > 0 && keys[t - 1] == 'constructor'))) {
throw new TypeError('JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
}
if (validateOperation) {
if (existingPathFragment === undefined) {
Expand Down
7 changes: 5 additions & 2 deletions src/core.ts
Expand Up @@ -251,8 +251,11 @@ export function applyOperation<T>(document: T, operation: Operation, validateOpe
key = unescapePathComponent(key);
}

if(banPrototypeModifications && key == '__proto__') {
throw new TypeError('JSON-Patch: modifying `__proto__` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
if(banPrototypeModifications &&
(key == '__proto__' ||
(key == 'prototype' && t>0 && keys[t-1] == 'constructor'))
) {
throw new TypeError('JSON-Patch: modifying `__proto__` or `constructor/prototype` prop is banned for security reasons, if this was on purpose, please set `banPrototypeModifications` flag false and pass it to this function. More info in fast-json-patch README');
}

if (validateOperation) {
Expand Down

0 comments on commit 7ad6af4

Please sign in to comment.