File tree 2 files changed +53
-0
lines changed
2 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -80,6 +80,12 @@ function decode (str) {
80
80
if ( ! match ) return
81
81
if ( match [ 1 ] !== undefined ) {
82
82
section = unsafe ( match [ 1 ] )
83
+ if ( section === '__proto__' ) {
84
+ // not allowed
85
+ // keep parsing the section, but don't attach it.
86
+ p = { }
87
+ return
88
+ }
83
89
p = out [ section ] = out [ section ] || { }
84
90
return
85
91
}
@@ -94,6 +100,7 @@ function decode (str) {
94
100
// Convert keys with '[]' suffix to an array
95
101
if ( key . length > 2 && key . slice ( - 2 ) === '[]' ) {
96
102
key = key . substring ( 0 , key . length - 2 )
103
+ if ( key === '__proto__' ) return
97
104
if ( ! p [ key ] ) {
98
105
p [ key ] = [ ]
99
106
} else if ( ! Array . isArray ( p [ key ] ) ) {
@@ -125,6 +132,7 @@ function decode (str) {
125
132
var l = parts . pop ( )
126
133
var nl = l . replace ( / \\ \. / g, '.' )
127
134
parts . forEach ( function ( part , _ , __ ) {
135
+ if ( part === '__proto__' ) return
128
136
if ( ! p [ part ] || typeof p [ part ] !== 'object' ) p [ part ] = { }
129
137
p = p [ part ]
130
138
} )
Original file line number Diff line number Diff line change
1
+ var ini = require ( '../' )
2
+ var t = require ( 'tap' )
3
+
4
+ var data = `
5
+ __proto__ = quux
6
+ foo = baz
7
+ [__proto__]
8
+ foo = bar
9
+ [other]
10
+ foo = asdf
11
+ [kid.__proto__.foo]
12
+ foo = kid
13
+ [arrproto]
14
+ hello = snyk
15
+ __proto__[] = you did a good job
16
+ __proto__[] = so you deserve arrays
17
+ thanks = true
18
+ `
19
+ var res = ini . parse ( data )
20
+ t . deepEqual ( res , {
21
+ foo : 'baz' ,
22
+ other : {
23
+ foo : 'asdf' ,
24
+ } ,
25
+ kid : {
26
+ foo : {
27
+ foo : 'kid' ,
28
+ } ,
29
+ } ,
30
+ arrproto : {
31
+ hello : 'snyk' ,
32
+ thanks : true ,
33
+ } ,
34
+ } )
35
+ t . equal ( res . __proto__ , Object . prototype )
36
+ t . equal ( res . kid . __proto__ , Object . prototype )
37
+ t . equal ( res . kid . foo . __proto__ , Object . prototype )
38
+ t . equal ( res . arrproto . __proto__ , Object . prototype )
39
+ t . equal ( Object . prototype . foo , undefined )
40
+ t . equal ( Object . prototype [ 0 ] , undefined )
41
+ t . equal ( Object . prototype [ '0' ] , undefined )
42
+ t . equal ( Object . prototype [ 1 ] , undefined )
43
+ t . equal ( Object . prototype [ '1' ] , undefined )
44
+ t . equal ( Array . prototype [ 0 ] , undefined )
45
+ t . equal ( Array . prototype [ 1 ] , undefined )
You can’t perform that action at this time.
0 commit comments