labstack / echo

High performance, minimalist Go web framework
https://echo.labstack.com
MIT License
29.62k stars 2.22k forks source link

static middleware: path ist unescaped twice for file names, leading to not downloadable content #2599

Open georgmu opened 7 months ago

georgmu commented 7 months ago

Issue Description

Given a file on disk with a percent sign in its name, it is not possible to download it using echo's static middleware.

Given some file names:

It is not possible to download these files using the static middleware.

Checklist

Expected behaviour

The standard way to download them would be using the folowing paths:

Actual behaviour

Background is that url.Path in http.Request is already escaped (as the documentation for url.Path suggests), but echo is unescaping it again.

I tried to generate a fix. For the non-embedded case this is solved by simply removing the explicit url.PathUnescape call in static.go (see https://github.com/georgmu/echo/commit/852dedeca2a22a0b6967e71f69cbb0823959a198 which also contains some test cases). I haven't created a merge request yet, as the embedding using groups or path patterns is a bit more complicated (I haven't fully understand the case for the disablePathUnescaping toggle).

Steps to reproduce / Working code to debug

See test cases in https://github.com/georgmu/echo/commit/852dedeca2a22a0b6967e71f69cbb0823959a198

Version/commit

master ( commit fa70db8 )