@@ -156,6 +156,24 @@ describe("verifyJsonContentType middleware", () => {
156156 expect ( response . statusCode ) . toBe ( 415 )
157157 expect ( response . text ) . toContain ( "Multiple Content-Type values are not allowed" )
158158 } )
159+
160+ it ( "returns 415 for semicolon-smuggled MIME type" , async ( ) => {
161+ const response = await request ( routeTester )
162+ . post ( "/json-endpoint" )
163+ . set ( "Content-Type" , "application/json; text/plain" )
164+ . send ( '{"test":"data"}' )
165+ expect ( response . statusCode ) . toBe ( 415 )
166+ expect ( response . text ) . toContain ( "Multiple Content-Type values are not allowed" )
167+ } )
168+
169+ it ( "returns 415 for semicolon-smuggled MIME type with valid parameter" , async ( ) => {
170+ const response = await request ( routeTester )
171+ . post ( "/json-endpoint" )
172+ . set ( "Content-Type" , "application/json; charset=utf-8; text/plain" )
173+ . send ( '{"test":"data"}' )
174+ expect ( response . statusCode ) . toBe ( 415 )
175+ expect ( response . text ) . toContain ( "Multiple Content-Type values are not allowed" )
176+ } )
159177} )
160178
161179describe ( "verifyTextContentType middleware" , ( ) => {
@@ -204,6 +222,15 @@ describe("verifyTextContentType middleware", () => {
204222 expect ( response . statusCode ) . toBe ( 415 )
205223 expect ( response . text ) . toContain ( "Multiple Content-Type values are not allowed" )
206224 } )
225+
226+ it ( "returns 415 for semicolon-smuggled MIME type" , async ( ) => {
227+ const response = await request ( routeTester )
228+ . post ( "/text-endpoint" )
229+ . set ( "Content-Type" , "text/plain; application/json" )
230+ . send ( "hello" )
231+ expect ( response . statusCode ) . toBe ( 415 )
232+ expect ( response . text ) . toContain ( "Multiple Content-Type values are not allowed" )
233+ } )
207234} )
208235
209236describe ( "verifyEitherContentType middleware" , ( ) => {
@@ -262,4 +289,13 @@ describe("verifyEitherContentType middleware", () => {
262289 expect ( response . statusCode ) . toBe ( 415 )
263290 expect ( response . text ) . toContain ( "Multiple Content-Type values are not allowed" )
264291 } )
292+
293+ it ( "returns 415 for semicolon-smuggled MIME type" , async ( ) => {
294+ const response = await request ( routeTester )
295+ . post ( "/either-endpoint" )
296+ . set ( "Content-Type" , "application/json; text/plain" )
297+ . send ( '{"test":"data"}' )
298+ expect ( response . statusCode ) . toBe ( 415 )
299+ expect ( response . text ) . toContain ( "Multiple Content-Type values are not allowed" )
300+ } )
265301} )
0 commit comments