File tree 2 files changed +12
-1
lines changed
2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -6,8 +6,17 @@ export default function klona(x) {
6
6
if ( str === '[object Object]' ) {
7
7
tmp = { } ;
8
8
for ( k in x ) {
9
+ if ( k === '__proto__' ) {
10
+ Object . defineProperty ( tmp , k , {
11
+ value : klona ( x [ k ] ) ,
12
+ configurable : 1 ,
13
+ enumerable : 1 ,
14
+ writable : 1 ,
15
+ } ) ;
16
+ } else {
9
17
tmp [ k ] = klona ( x [ k ] ) ;
10
18
}
19
+ }
11
20
return tmp ;
12
21
}
13
22
Original file line number Diff line number Diff line change @@ -99,16 +99,17 @@ test('constructor :: pollution', t => {
99
99
) ;
100
100
101
101
t . not ( ( { } ) [ 'a0' ] , true , 'Safe POJO' ) ;
102
+ t . not ( new Object ( ) [ 'a0' ] , true , 'Safe Object' ) ;
102
103
t . not ( input [ 'a0' ] , true , 'Safe input' ) ;
103
104
t . not ( output [ 'a0' ] , true , 'Safe output' ) ;
104
105
105
106
t . end ( ) ;
106
107
} ) ;
107
108
108
109
110
+ // @see https://snyk.io/vuln/SNYK-JS-LODASH-450202
109
111
test ( 'prototype :: pollution' , t => {
110
112
const payload = '{"__proto__":{"a0":true}}' ;
111
-
112
113
const input = JSON . parse ( payload ) ;
113
114
const output = klona ( input ) ;
114
115
@@ -118,6 +119,7 @@ test('prototype :: pollution', t => {
118
119
) ;
119
120
120
121
t . not ( ( { } ) [ 'a0' ] , true , 'Safe POJO' ) ;
122
+ t . not ( new Object ( ) [ 'a0' ] , true , 'Safe Object' ) ;
121
123
t . not ( input [ 'a0' ] , true , 'Safe input' ) ;
122
124
t . not ( output [ 'a0' ] , true , 'Safe output' ) ;
123
125
You can’t perform that action at this time.
0 commit comments