@@ -99,6 +99,10 @@ describe.each([
9999 path . resolve ( outputPath , "image.svg" ) ,
100100 "svg image" ,
101101 ) ;
102+ instance . context . outputFileSystem . writeFileSync (
103+ path . resolve ( outputPath , "image image.svg" ) ,
104+ "svg image" ,
105+ ) ;
102106 instance . context . outputFileSystem . writeFileSync (
103107 path . resolve ( outputPath , "byte-length.html" ) ,
104108 "\u00bd + \u00bc = \u00be" ,
@@ -183,6 +187,36 @@ describe.each([
183187 expect ( response . headers [ "content-type" ] ) . toEqual ( "image/svg+xml" ) ;
184188 } ) ;
185189
190+ it ( 'should return the "200" code for the "GET" request to the "image.svg" file with "/../"' , async ( ) => {
191+ const fileData = instance . context . outputFileSystem . readFileSync (
192+ path . resolve ( outputPath , "image.svg" ) ,
193+ ) ;
194+
195+ const response = await req . get ( "/public/../image.svg" ) ;
196+
197+ expect ( response . statusCode ) . toEqual ( 200 ) ;
198+ expect ( response . headers [ "content-length" ] ) . toEqual (
199+ fileData . byteLength . toString ( ) ,
200+ ) ;
201+ expect ( response . headers [ "content-type" ] ) . toEqual ( "image/svg+xml" ) ;
202+ } ) ;
203+
204+ it ( 'should return the "200" code for the "GET" request to the "image.svg" file with "/../../../"' , async ( ) => {
205+ const fileData = instance . context . outputFileSystem . readFileSync (
206+ path . resolve ( outputPath , "image.svg" ) ,
207+ ) ;
208+
209+ const response = await req . get (
210+ "/public/assets/images/../../../image.svg" ,
211+ ) ;
212+
213+ expect ( response . statusCode ) . toEqual ( 200 ) ;
214+ expect ( response . headers [ "content-length" ] ) . toEqual (
215+ fileData . byteLength . toString ( ) ,
216+ ) ;
217+ expect ( response . headers [ "content-type" ] ) . toEqual ( "image/svg+xml" ) ;
218+ } ) ;
219+
186220 it ( 'should return the "200" code for the "GET" request to the directory' , async ( ) => {
187221 const fileData = fs . readFileSync (
188222 path . resolve ( __dirname , "./fixtures/index.html" ) ,
@@ -263,7 +297,7 @@ describe.each([
263297 `bytes */${ codeLength } ` ,
264298 ) ;
265299 expect ( response . headers [ "content-type" ] ) . toEqual (
266- "text/html; charset=UTF -8" ,
300+ "text/html; charset=utf -8" ,
267301 ) ;
268302 expect ( response . text ) . toEqual (
269303 `<!DOCTYPE html>
@@ -447,6 +481,29 @@ describe.each([
447481 false ,
448482 ) ;
449483 } ) ;
484+
485+ it ( 'should return the "200" code for the "GET" request to the "image image.svg" file' , async ( ) => {
486+ const fileData = instance . context . outputFileSystem . readFileSync (
487+ path . resolve ( outputPath , "image image.svg" ) ,
488+ ) ;
489+
490+ const response = await req . get ( "/image image.svg" ) ;
491+
492+ expect ( response . statusCode ) . toEqual ( 200 ) ;
493+ expect ( response . headers [ "content-length" ] ) . toEqual (
494+ fileData . byteLength . toString ( ) ,
495+ ) ;
496+ expect ( response . headers [ "content-type" ] ) . toEqual ( "image/svg+xml" ) ;
497+ } ) ;
498+
499+ it ( 'should return the "404" code for the "GET" request to the "%FF" file' , async ( ) => {
500+ const response = await req . get ( "/%FF" ) ;
501+
502+ expect ( response . statusCode ) . toEqual ( 404 ) ;
503+ expect ( response . headers [ "content-type" ] ) . toEqual (
504+ "text/html; charset=utf-8" ,
505+ ) ;
506+ } ) ;
450507 } ) ;
451508
452509 describe ( 'should not work with the broken "publicPath" option' , ( ) => {
@@ -2032,7 +2089,7 @@ describe.each([
20322089
20332090 expect ( response . statusCode ) . toEqual ( 500 ) ;
20342091 expect ( response . headers [ "content-type" ] ) . toEqual (
2035- "text/html; charset=UTF -8" ,
2092+ "text/html; charset=utf -8" ,
20362093 ) ;
20372094 expect ( response . text ) . toEqual (
20382095 "<!DOCTYPE html>\n" +
@@ -2113,7 +2170,7 @@ describe.each([
21132170
21142171 expect ( response . statusCode ) . toEqual ( 404 ) ;
21152172 expect ( response . headers [ "content-type" ] ) . toEqual (
2116- "text/html; charset=UTF -8" ,
2173+ "text/html; charset=utf -8" ,
21172174 ) ;
21182175 expect ( response . text ) . toEqual (
21192176 "<!DOCTYPE html>\n" +
@@ -2575,6 +2632,7 @@ describe.each([
25752632 output : {
25762633 filename : "bundle.js" ,
25772634 path : path . resolve ( __dirname , "./outputs/write-to-disk-true" ) ,
2635+ publicPath : "/public/" ,
25782636 } ,
25792637 } ) ;
25802638
@@ -2598,7 +2656,7 @@ describe.each([
25982656
25992657 it ( "should find the bundle file on disk" , ( done ) => {
26002658 request ( app )
2601- . get ( "/bundle.js" )
2659+ . get ( "/public/ bundle.js" )
26022660 . expect ( 200 , ( error ) => {
26032661 if ( error ) {
26042662 return done ( error ) ;
@@ -2632,6 +2690,25 @@ describe.each([
26322690 ) ;
26332691 } ) ;
26342692 } ) ;
2693+
2694+ it ( "should not allow to get files above root" , async ( ) => {
2695+ const response = await req . get ( "/public/..%2f../middleware.test.js" ) ;
2696+
2697+ expect ( response . statusCode ) . toEqual ( 403 ) ;
2698+ expect ( response . headers [ "content-type" ] ) . toEqual (
2699+ "text/html; charset=utf-8" ,
2700+ ) ;
2701+ expect ( response . text ) . toEqual ( `<!DOCTYPE html>
2702+ <html lang="en">
2703+ <head>
2704+ <meta charset="utf-8">
2705+ <title>Error</title>
2706+ </head>
2707+ <body>
2708+ <pre>Forbidden</pre>
2709+ </body>
2710+ </html>` ) ;
2711+ } ) ;
26352712 } ) ;
26362713
26372714 describe ( 'should work with "true" value when the `output.clean` is `true`' , ( ) => {
0 commit comments