@@ -158,7 +158,7 @@ function buildParam(key: string, value: any, traditional?: boolean): Array<strin
158158* @param traditional Boolean Use the old URI template standard (RFC6570)
159159* @returns The generated query string, excluding leading '?'.
160160*/
161- export function buildQueryString ( params : Object , traditional ?: Boolean ) : string {
161+ export function buildQueryString ( params ? : Object , traditional ?: boolean ) : string {
162162 let pairs = [ ] ;
163163 let keys = Object . keys ( params || { } ) . sort ( ) ;
164164 for ( let i = 0 , len = keys . length ; i < len ; i ++ ) {
@@ -203,16 +203,19 @@ function processScalarParam(existedParam: Object, value: Object): Object {
203203* @param keys Collection of keys related to this parameter.
204204* @param value Parameter value to append.
205205*/
206- function parseComplexParam ( queryParams : Object , keys : Object , value : any ) : void {
206+ function parseComplexParam ( queryParams : Object , keys : ( string | number ) [ ] , value : any ) : void {
207207 let currentParams = queryParams ;
208208 let keysLastIndex = keys . length - 1 ;
209209 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+ }
211214 if ( j < keysLastIndex ) {
212215 // The value has to be an array or a false value
213216 // It can happen that the value is no array if the key was repeated with traditional style like `list=1&list[]=2`
214217 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 ) ? { } : [ ] ) ;
216219 } else {
217220 currentParams = currentParams [ key ] = value ;
218221 }
0 commit comments