Skip to content
Myr

Merge commit from fork

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(serve-static): replace decodeURIComponent with tryDecodeURI to prevent auth bypass Co-authored-by: Taku Amano <taku@taaas.jp> * fix(serve-static): replace decodeURIComponent with tryDecodeURI Co-authored-by: Taku Amano <taku@taaas.jp> Co-authored-by: EdamAmex <edame8080@gmail.com> * fix(serve-static): streamline app.use syntax and ensure consistent string quotes in tests ---------

authored by techfish · committed by GitHub · parent 0768232 · Browse files · 3 files+26 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: Taku Amano <taku@taaas.jp>
  • Co-authored-by: EdamAmex <edame8080@gmail.com>

Diff stats

3 files+26 added−2 removed

  • tests:+23 added−0 removed
  • other:+3 added−2 removed

3 files+26 added−2 removed

modified:src/middleware/serve-static/index.test.ts+23 added
265 unmodified lines
266267 const res = await app.request('///etc/passwd')268 expect(await res.text()).toBe('Hello in etc/passwd')269 })270271 it('Should not allow bypass via path mismatch between middleware and serveStatic', async () => {272 const app = new Hono()273274 app.use('/admin/*', async (c, next) => {275 c.header('X-Authorized', 'true')276 await next()277 })278279 const serveStatic = baseServeStatic({280 getContent,281 root: '.',282 })283 app.use('/*', serveStatic)284285 const res = await app.request('/admin/secret.txt')286 expect(res.headers.get('X-Authorized')).toBe('true')287 expect(await res.text()).toBe('Hello in admin/secret.txt')288289 const res2 = await app.request('/admin%2Fsecret.txt')290 expect(res2.headers.get('X-Authorized')).toBeNull()291 expect(await res2.text()).toBe('Hello in admin%2Fsecret.txt')292 })293 })294})
modified:src/middleware/serve-static/index.ts+2 added-1 removed
modified:src/utils/url.ts+1 added-1 removed
99 unmodified lines
100 * @example101 * tryDecodeURI('Hello%20World') // 'Hello World'102 * tryDecodeURI('Hello%20World/%A4%A2') // 'Hello World/%A4%A2'103 */104const tryDecodeURI = (str: string) => tryDecode(str, decodeURI)104export const tryDecodeURI = (str: string) => tryDecode(str, decodeURI)105106export const getPath = (request: Request): string => {107 const url = request.url108 const start = url.indexOf('/', url.indexOf(':') + 4)
211 unmodified lines