Skip to content

Commit 751ba41

Browse files
authored
Merge commit from fork
1 parent f0b094d commit 751ba41

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/middleware/serve-static/index.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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
'*',

src/middleware/serve-static/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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 {

0 commit comments

Comments
 (0)