@@ -21,6 +21,7 @@ describe('invalid query strings', () => {
2121 const url = `/?${ sp } `
2222 const res = await get ( url )
2323 expect ( res . statusCode ) . toBe ( 400 )
24+ expect ( res . headers [ 'content-type' ] ) . toMatch ( 'text/plain' )
2425 expect ( res . headers [ 'cache-control' ] ) . toMatch ( 'no-store' )
2526 expect ( res . headers [ 'cache-control' ] ) . toMatch ( 'private' )
2627 } )
@@ -69,14 +70,20 @@ describe('invalid query strings', () => {
6970 const url = `/en?query[foo]=bar`
7071 const res = await get ( url )
7172 expect ( res . statusCode ) . toBe ( 400 )
72- expect ( res . body ) . toMatch ( 'Invalid query string key (query)' )
73+ expect ( res . headers [ 'content-type' ] ) . toMatch ( 'text/plain' )
74+ expect ( res . body ) . toMatch ( 'Invalid query string' )
75+ // Must not reflect the user-supplied key name
76+ expect ( res . body ) . not . toContain ( '(query)' )
7377 } )
7478
7579 test ( 'query string keys with square brackets' , async ( ) => {
7680 const url = `/?constructor[foo][bar]=buz`
7781 const res = await get ( url )
7882 expect ( res . statusCode ) . toBe ( 400 )
79- expect ( res . body ) . toMatch ( 'Invalid query string key (constructor)' )
83+ expect ( res . headers [ 'content-type' ] ) . toMatch ( 'text/plain' )
84+ expect ( res . body ) . toMatch ( 'Invalid query string' )
85+ // Must not reflect the user-supplied key name
86+ expect ( res . body ) . not . toContain ( '(constructor)' )
8087 } )
8188
8289 test ( 'bad tool query string with Chinese URL-encoded characters' , async ( ) => {
@@ -86,6 +93,14 @@ describe('invalid query strings', () => {
8693 expect ( res . statusCode ) . toBe ( 302 )
8794 expect ( res . headers . location ) . toBe ( '/?tool=azure_data_studio' )
8895 } )
96+
97+ test ( 'XSS payloads in bracket query keys are not reflected' , async ( ) => {
98+ const res = await get ( '/en?%3Cscript%3Ealert()%3C/script%3E[]' )
99+ expect ( res . statusCode ) . toBe ( 400 )
100+ expect ( res . headers [ 'content-type' ] ) . toMatch ( 'text/plain' )
101+ expect ( res . body ) . not . toContain ( '<script>' )
102+ expect ( res . body ) . not . toContain ( 'alert' )
103+ } )
89104} )
90105
91106function randomCharacters ( length : number ) {
0 commit comments