Skip to content

Commit 6a1e3ef

Browse files
committed
Remove object path functions.
- Remove `util.getPath`, `util.setPath`, and `util.deletePath`. - These are unused in `forge` itself. - Path processing has potential security issues. (For `setPath` in particular). - `lodash` has better replacements: `get`, `set`, and `unset`. - See also: - CHANGELOG.md 0.9.2 entry. - https://snyk.io/vuln/SNYK-JS-NODEFORGE-598677 - https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-7720
1 parent 30d560c commit 6a1e3ef

File tree

3 files changed

+13
-100
lines changed

3 files changed

+13
-100
lines changed

CHANGELOG.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,21 @@
11
Forge ChangeLog
22
===============
33

4+
### Changed
45
- **BREAKING**: Node.js 4 no longer supported. The code *may* still work, and
56
non-invasive patches to keep it working will be considered. However, more
6-
modern tools no longer support very old Node.js versions making testing
7-
difficult.
7+
modern tools no longer support old Node.js versions making testing difficult.
8+
9+
### Removed
10+
- **BREAKING**: Remove `util.getPath`, `util.setPath`, and `util.deletePath`.
11+
`util.setPath` had a potential prototype pollution security issue when used
12+
with unsafe inputs. These functions are not used by `forge` itself. They date
13+
from an early time when `forge` was targeted at providing general helper
14+
functions. The library direction changed to be more focused on cryptography.
15+
Many other excellent libraries are more suitable for general utilities. If
16+
you need a replacement for these functions, consier `get`, `set`, and `unset`
17+
from [lodash](https://lodash.com/). But also consider the potential similar
18+
security issues with those APIs.
819

920
## 0.9.2 - 2019-09-01
1021

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,8 +2035,6 @@ When using this code please keep the following in mind:
20352035
- Certain features in this library are less susceptible to attacks depending on
20362036
usage. This primarily includes features that deal with data format
20372037
manipulation or those that are not involved in communication.
2038-
- Do not pass unsafe inputs to `util.setPath`. Doing so could expose a
2039-
prototype pollution security issue.
20402038

20412039
Library Background
20422040
------------------

lib/util.js

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -2513,102 +2513,6 @@ util.makeLink = function(path, query, fragment) {
25132513
((fragment.length > 0) ? ('#' + fragment) : '');
25142514
};
25152515

2516-
/**
2517-
* Follows a path of keys deep into an object hierarchy and set a value.
2518-
* If a key does not exist or it's value is not an object, create an
2519-
* object in it's place. This can be destructive to a object tree if
2520-
* leaf nodes are given as non-final path keys.
2521-
* Used to avoid exceptions from missing parts of the path.
2522-
*
2523-
* SECURITY NOTE: Do not use unsafe inputs. Doing so could expose a prototype
2524-
* pollution security issue.
2525-
*
2526-
* @param object the starting object.
2527-
* @param keys an array of string keys.
2528-
* @param value the value to set.
2529-
*/
2530-
util.setPath = function(object, keys, value) {
2531-
// need to start at an object
2532-
if(typeof(object) === 'object' && object !== null) {
2533-
var i = 0;
2534-
var len = keys.length;
2535-
while(i < len) {
2536-
var next = keys[i++];
2537-
if(i == len) {
2538-
// last
2539-
object[next] = value;
2540-
} else {
2541-
// more
2542-
var hasNext = (next in object);
2543-
if(!hasNext ||
2544-
(hasNext && typeof(object[next]) !== 'object') ||
2545-
(hasNext && object[next] === null)) {
2546-
object[next] = {};
2547-
}
2548-
object = object[next];
2549-
}
2550-
}
2551-
}
2552-
};
2553-
2554-
/**
2555-
* Follows a path of keys deep into an object hierarchy and return a value.
2556-
* If a key does not exist, create an object in it's place.
2557-
* Used to avoid exceptions from missing parts of the path.
2558-
*
2559-
* @param object the starting object.
2560-
* @param keys an array of string keys.
2561-
* @param _default value to return if path not found.
2562-
*
2563-
* @return the value at the path if found, else default if given, else
2564-
* undefined.
2565-
*/
2566-
util.getPath = function(object, keys, _default) {
2567-
var i = 0;
2568-
var len = keys.length;
2569-
var hasNext = true;
2570-
while(hasNext && i < len &&
2571-
typeof(object) === 'object' && object !== null) {
2572-
var next = keys[i++];
2573-
hasNext = next in object;
2574-
if(hasNext) {
2575-
object = object[next];
2576-
}
2577-
}
2578-
return (hasNext ? object : _default);
2579-
};
2580-
2581-
/**
2582-
* Follow a path of keys deep into an object hierarchy and delete the
2583-
* last one. If a key does not exist, do nothing.
2584-
* Used to avoid exceptions from missing parts of the path.
2585-
*
2586-
* @param object the starting object.
2587-
* @param keys an array of string keys.
2588-
*/
2589-
util.deletePath = function(object, keys) {
2590-
// need to start at an object
2591-
if(typeof(object) === 'object' && object !== null) {
2592-
var i = 0;
2593-
var len = keys.length;
2594-
while(i < len) {
2595-
var next = keys[i++];
2596-
if(i == len) {
2597-
// last
2598-
delete object[next];
2599-
} else {
2600-
// more
2601-
if(!(next in object) ||
2602-
(typeof(object[next]) !== 'object') ||
2603-
(object[next] === null)) {
2604-
break;
2605-
}
2606-
object = object[next];
2607-
}
2608-
}
2609-
}
2610-
};
2611-
26122516
/**
26132517
* Check if an object is empty.
26142518
*

0 commit comments

Comments
 (0)