Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc914124

Browse files
committed
feat: patch 4.2.0 with fixes forCVE-2020-8116
1 parent70f7ed8 commitc914124

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-
constm=require('./');
3+
constm=require('.');
44

55
bench('get',()=>{
66
constf1={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
constisObj=require('is-obj');
33

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

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

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

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

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

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

6280
for(leti=0;i<pathArr.length;i++){
6381
constp=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
importtestfrom'ava';
2-
importmfrom'./';
2+
importmfrom'.';
33

44
test('get',t=>{
55
constf1={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)

[8]ページ先頭

©2009-2025 Movatter.jp