Skip to content

Commit

Permalink
Merge pull request #2 from alromh87/enhancePR
Browse files Browse the repository at this point in the history
Fix Prototype Pollution
  • Loading branch information
JamieSlome committed Oct 22, 2020
2 parents 2ad6af4 + 7d88fd2 commit c397b6f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,11 @@ export function applyOperation<T>(document: T, operation: Operation, validateOpe
}
while (true) {
key = keys[t];

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 c397b6f

Please sign in to comment.