-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prototype pollution vulnerability working tests
- Loading branch information
Showing
3 changed files
with
41 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 1,5 @@ | ||
'use strict'; | ||
|
||
|
||
/* ! | ||
* Chai - pathval utility | ||
* Copyright(c) 2012-2014 Jake Luer <[email protected]> | ||
|
@@ -77,6 76,13 @@ function parsePath(path) { | |
var str = path.replace(/([^\\])\[/g, '$1.['); | ||
var parts = str.match(/(\\\.|[^.] ?) /g); | ||
return parts.map(function mapMatches(value) { | ||
if ( | ||
value === 'constructor' || | ||
value === '__proto__' || | ||
value === 'prototype' | ||
) { | ||
return {}; | ||
} | ||
var regexp = /^\[(\d )\]$/; | ||
var mArr = regexp.exec(value); | ||
var parsed = null; | ||
|
@@ -108,7 114,7 @@ function parsePath(path) { | |
function internalGetPathValue(obj, parsed, pathDepth) { | ||
var temporaryValue = obj; | ||
var res = null; | ||
pathDepth = (typeof pathDepth === 'undefined' ? parsed.length : pathDepth); | ||
pathDepth = typeof pathDepth === 'undefined' ? parsed.length : pathDepth; | ||
|
||
for (var i = 0; i < pathDepth; i ) { | ||
var part = parsed[i]; | ||
|
@@ -119,7 125,7 @@ function internalGetPathValue(obj, parsed, pathDepth) { | |
temporaryValue = temporaryValue[part.p]; | ||
} | ||
|
||
if (i === (pathDepth - 1)) { | ||
if (i === pathDepth - 1) { | ||
res = temporaryValue; | ||
} | ||
} | ||
|
@@ -153,7 159,7 @@ function internalSetPathValue(obj, val, parsed) { | |
part = parsed[i]; | ||
|
||
// If it's the last part of the path, we set the 'propName' value with the property name | ||
if (i === (pathDepth - 1)) { | ||
if (i === pathDepth - 1) { | ||
propName = typeof part.p === 'undefined' ? part.i : part.p; | ||
// Now we set the property with the name held by 'propName' on object with the desired val | ||
tempObj[propName] = val; | ||
|
@@ -200,7 206,10 @@ function getPathInfo(obj, path) { | |
var parsed = parsePath(path); | ||
var last = parsed[parsed.length - 1]; | ||
var info = { | ||
parent: parsed.length > 1 ? internalGetPathValue(obj, parsed, parsed.length - 1) : obj, | ||
parent: | ||
parsed.length > 1 ? | ||
internalGetPathValue(obj, parsed, parsed.length - 1) : | ||
obj, | ||
name: last.p || last.i, | ||
value: internalGetPathValue(obj, parsed), | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters