File tree Expand file tree Collapse file tree
src/middleware/serve-static Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,6 +79,15 @@ describe('Serve Static Middleware', () => {
7979 expect ( await res . text ( ) ) . toBe ( '404 Not Found' )
8080 } )
8181
82+ it ( 'Should not allow a backslash separator injection - /static/admin%5Csecret.txt' , async ( ) => {
83+ const res = await app . fetch ( {
84+ method : 'GET' ,
85+ url : 'http://localhost/static/admin%5Csecret.txt' ,
86+ } as Request )
87+ expect ( res . status ) . toBe ( 404 )
88+ expect ( await res . text ( ) ) . toBe ( '404 Not Found' )
89+ } )
90+
8291 it ( 'Should return a pre-compressed zstd response - /static/hello.html' , async ( ) => {
8392 const app = new Hono ( ) . use (
8493 '*' ,
Original file line number Diff line number Diff line change @@ -64,7 +64,7 @@ export const serveStatic = <E extends Env = Env>(
6464 } else {
6565 try {
6666 filename = tryDecodeURI ( c . req . path )
67- if ( / (?: ^ | [ \/ \\ ] ) \. { 1 , 2 } (?: $ | [ \/ \\ ] ) | [ \/ \\ ] { 2 , } / . test ( filename ) ) {
67+ if ( / (?: ^ | [ \/ \\ ] ) \. { 1 , 2 } (?: $ | [ \/ \\ ] ) | [ \/ \\ ] { 2 , } | \\ / . test ( filename ) ) {
6868 throw new Error ( )
6969 }
7070 } catch {
You can’t perform that action at this time.
0 commit comments