Skip to content

Commit 025c30f

Browse files
authored
Merge commit from fork
1 parent 6cdb5a7 commit 025c30f

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/serve-static.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export const serveStatic = <E extends Env = any>(
111111
} else {
112112
try {
113113
filename = tryDecodeURI(c.req.path)
114-
if (/(?:^|[\/\\])\.\.(?:$|[\/\\])/.test(filename)) {
114+
if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}/.test(filename)) {
115115
throw new Error()
116116
}
117117
} catch {

test/serve-static.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ describe('Serve Static Middleware', () => {
381381
expect(res2.status).toBe(404)
382382
expect(res2.headers['x-authorized']).toBeUndefined()
383383
expect(res2.text).not.toBe('secret')
384+
385+
const res3 = await request(server).get('/static//admin/secret.txt')
386+
expect(res3.status).toBe(404)
384387
})
385388
})
386389

0 commit comments

Comments
 (0)