@@ -158,7 +158,7 @@ function buildParam(key: string, value: any, traditional?: boolean): Array<strin
158
158
* @param traditional Boolean Use the old URI template standard (RFC6570)
159
159
* @returns The generated query string, excluding leading '?'.
160
160
*/
161
- export function buildQueryString ( params : Object , traditional ?: Boolean ) : string {
161
+ export function buildQueryString ( params ? : Object , traditional ?: boolean ) : string {
162
162
let pairs = [ ] ;
163
163
let keys = Object . keys ( params || { } ) . sort ( ) ;
164
164
for ( let i = 0 , len = keys . length ; i < len ; i ++ ) {
@@ -203,16 +203,19 @@ function processScalarParam(existedParam: Object, value: Object): Object {
203
203
* @param keys Collection of keys related to this parameter.
204
204
* @param value Parameter value to append.
205
205
*/
206
- function parseComplexParam ( queryParams : Object , keys : Object , value : any ) : void {
206
+ function parseComplexParam ( queryParams : Object , keys : ( string | number ) [ ] , value : any ) : void {
207
207
let currentParams = queryParams ;
208
208
let keysLastIndex = keys . length - 1 ;
209
209
for ( let j = 0 ; j <= keysLastIndex ; j ++ ) {
210
- let key = keys [ j ] === '' ? currentParams . length : keys [ j ] ;
210
+ let key = keys [ j ] === '' ? ( currentParams as any ) . length : keys [ j ] ;
211
+ if ( key === '__proto__' ) {
212
+ throw new Error ( 'Prototype pollution detected.' ) ;
213
+ }
211
214
if ( j < keysLastIndex ) {
212
215
// The value has to be an array or a false value
213
216
// It can happen that the value is no array if the key was repeated with traditional style like `list=1&list[]=2`
214
217
let prevValue = ! currentParams [ key ] || typeof currentParams [ key ] === 'object' ? currentParams [ key ] : [ currentParams [ key ] ] ;
215
- currentParams = currentParams [ key ] = prevValue || ( isNaN ( keys [ j + 1 ] ) ? { } : [ ] ) ;
218
+ currentParams = currentParams [ key ] = prevValue || ( isNaN ( keys [ j + 1 ] as number ) ? { } : [ ] ) ;
216
219
} else {
217
220
currentParams = currentParams [ key ] = value ;
218
221
}
0 commit comments