Skip to content

Commit c914124

Browse files
committed
feat: patch 4.2.0 with fixes for CVE-2020-8116
1 parent 70f7ed8 commit c914124

File tree

5 files changed

+32
-5
lines changed

5 files changed

+32
-5
lines changed

bench.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22
/* globals bench */
3-
const m = require('./');
3+
const m = require('.');
44

55
bench('get', () => {
66
const f1 = {foo: {bar: 1}};

index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
'use strict';
22
const isObj = require('is-obj');
33

4+
const disallowedKeys = [
5+
'__proto__',
6+
'prototype',
7+
'constructor'
8+
];
9+
10+
const isValidPath = pathSegments => !pathSegments.some(segment => disallowedKeys.includes(segment));
11+
412
function getPathSegments(path) {
513
const pathArr = path.split('.');
614
const parts = [];
@@ -16,6 +24,10 @@ function getPathSegments(path) {
1624
parts.push(p);
1725
}
1826

27+
if (!isValidPath(parts)) {
28+
return [];
29+
}
30+
1931
return parts;
2032
}
2133

@@ -26,6 +38,9 @@ module.exports = {
2638
}
2739

2840
const pathArr = getPathSegments(path);
41+
if (pathArr.length === 0) {
42+
return;
43+
}
2944

3045
for (let i = 0; i < pathArr.length; i++) {
3146
if (!Object.prototype.propertyIsEnumerable.call(obj, pathArr[i])) {
@@ -58,6 +73,9 @@ module.exports = {
5873

5974
const root = obj;
6075
const pathArr = getPathSegments(path);
76+
if (pathArr.length === 0) {
77+
return;
78+
}
6179

6280
for (let i = 0; i < pathArr.length; i++) {
6381
const p = pathArr[i];

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dot-prop",
3-
"version": "4.2.0",
3+
"version": "4.2.1",
44
"description": "Get, set, or delete a property from a nested object using a dot path",
55
"license": "MIT",
66
"repository": "sindresorhus/dot-prop",
@@ -38,9 +38,9 @@
3838
"is-obj": "^1.0.0"
3939
},
4040
"devDependencies": {
41-
"ava": "*",
41+
"ava": "1.4.1",
4242
"matcha": "^0.7.0",
43-
"xo": "*"
43+
"xo": "0.24.0"
4444
},
4545
"xo": {
4646
"esnext": true

readme.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ Path of the property in the object, using `.` to separate each nested key.
8585

8686
Use `\\.` if you have a `.` in the key.
8787

88+
The following path components are invalid and results in `undefined` being returned: `__proto__`, `prototype`, `constructor`.
89+
8890
#### value
8991

9092
Type: `any`

test.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import m from './';
2+
import m from '.';
33

44
test('get', t => {
55
const f1 = {foo: {bar: 1}};
@@ -199,3 +199,10 @@ test('has', t => {
199199
t.is(m.has({'foo.baz': {bar: true}}, 'foo\\.baz.bar'), true);
200200
t.is(m.has({'fo.ob.az': {bar: true}}, 'fo\\.ob\\.az.bar'), true);
201201
});
202+
203+
test('prevent setting/getting `__proto__`', t => {
204+
m.set({}, '__proto__.unicorn', '🦄');
205+
t.not({}.unicorn, '🦄'); // eslint-disable-line no-use-extend-native/no-use-extend-native
206+
207+
t.is(m.get({}, '__proto__'), undefined);
208+
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy