File tree Expand file tree Collapse file tree 4 files changed +27
-19
lines changed
Expand file tree Collapse file tree 4 files changed +27
-19
lines changed Original file line number Diff line number Diff line change 11sudo : false
22language : node_js
33node_js :
4- - " 5"
54 - " 4"
6- - " 0.12"
7- - " 0.10"
8- - " 0.8"
9- before_install :
10- - ' if [ "${TRAVIS_NODE_VERSION}" == "0.8" ]; then npm install -g npm@2.14.15; fi'
5+ - " 6"
6+ - " 8"
7+ - " 9"
118script :
129 - " npm run test-travis"
1310after_script :
Original file line number Diff line number Diff line change @@ -25,15 +25,18 @@ function querystring(query) {
2525 , result = { }
2626 , part ;
2727
28- //
29- // Little nifty parsing hack, leverage the fact that RegExp.exec increments
30- // the lastIndex property so we can continue executing this loop until we've
31- // parsed all results.
32- //
33- for ( ;
34- part = parser . exec ( query ) ;
35- result [ decode ( part [ 1 ] ) ] = decode ( part [ 2 ] )
36- ) ;
28+ while ( part = parser . exec ( query ) ) {
29+ var key = decode ( part [ 1 ] )
30+ , value = decode ( part [ 2 ] ) ;
31+
32+ //
33+ // Prevent overriding of existing properties. This ensures that build-in
34+ // methods like `toString` or __proto__ are not overriden by malicious
35+ // querystrings.
36+ //
37+ if ( key in result ) continue ;
38+ result [ key ] = value ;
39+ }
3740
3841 return result ;
3942}
Original file line number Diff line number Diff line change 3131 },
3232 "homepage" : " https://github.com/unshiftio/querystringify" ,
3333 "devDependencies" : {
34- "assume" : " ~1.5.0 " ,
35- "istanbul" : " 0.4.x " ,
36- "mocha" : " ~3.5.0 " ,
37- "pre-commit" : " ~ 1.2.0 "
34+ "assume" : " ^2.0.1 " ,
35+ "istanbul" : " ^ 0.4.5 " ,
36+ "mocha" : " ^5.1.1 " ,
37+ "pre-commit" : " ^ 1.2.2 "
3838 }
3939}
Original file line number Diff line number Diff line change @@ -63,6 +63,14 @@ describe('querystringify', function () {
6363 assume ( obj . shizzle ) . equals ( 'mynizzle' ) ;
6464 } ) ;
6565
66+ it ( 'does not overide prototypes' , function ( ) {
67+ var obj = qs . parse ( '?toString&__proto__=lol' ) ;
68+
69+ assume ( obj ) . is . a ( 'object' ) ;
70+ assume ( obj . toString ) . is . a ( 'function' ) ;
71+ assume ( obj . __proto__ ) . does . not . equals ( 'lol' ) ;
72+ } ) ;
73+
6674 it ( 'works with querystring parameters without values' , function ( ) {
6775 var obj = qs . parse ( '?foo&bar=&shizzle=mynizzle' ) ;
6876
You can’t perform that action at this time.
0 commit comments