Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Fix Prototype Pollution #2

Merged
merged 2 commits into from
Oct 22, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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