You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It appears that the file system improvement (#2064) in the latest release v4.7.0 is breaking the backwards compatibility of static routes. Files that are registered with the Static method are no longer served on that route and a 404 is returned. This issue has already been briefly mentioned in the comments of #2064. I'd like to continue the discussion on this issue here and give a short example.
Checklist
Dependencies installed
No typos
Searched existing issues and docs
Expected behaviour
The Static method should work and files should be served the same as with <=4.6.3. In other words, the minor update should not change the behaviour of the Static method.
Actual behaviour
Static file routes registered with Static are not serving the given files when updating to echo v4.7.0.
Steps to reproduce
Create a file in the main directory, eg. index.html
It is limited to case when second parameter for e.Static is not a folder but a file. Although this seems to be "unintended" feature that e.Static can be used to serve single file. Second parameter is meant to be actually path (folder). https://echo.labstack.com/guide/static-files/#using-echostatic
Just to point out that serving single file with e.Static may not be that secure as e.Static takes everything from URL after your prefix (this case prefix = "" and uses it as suffix to your root (in this case ./index.html)
So if you have
e.Static("", "./index.html")
and for some odd reason that index.html is not a file but folder instead. We can download files from that folder by appending file name to request.
./
./main.go
./index.html/
./index.html/.htpasswd
with
x@x:~/code/$ curl -v http://localhost:8080/.htpasswd
* Trying 127.0.0.1:8080...
* Connected to localhost (127.0.0.1) port 8080 (#0)> GET /.htpass HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.74.0
> Accept: */*>* Mark bundle as not supporting multiuse
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Content-Length: 4
< Content-Type: text/plain; charset=utf-8
< Last-Modified: Wed, 09 Mar 2022 18:27:46 GMT
< Date: Wed, 09 Mar 2022 18:29:15 GMT
<
hi
* Connection #0 to host localhost left intact
Activity
aldas commentedon Mar 9, 2022
I can confirm that this happens.
It is limited to case when second parameter for
e.Staticis not a folder but a file. Although this seems to be "unintended" feature thate.Staticcan be used to serve single file. Second parameter is meant to be actually path (folder). https://echo.labstack.com/guide/static-files/#using-echostaticv4.6.3codeecho/echo.go
Lines 494 to 502 in 6b5e62b
Actually
e.File("/favicon.ico", "images/favicon.ico")is proper way to serve single file (in this casee.Static("", "index.html")I'll look what we can do with
e.Staticaldas commentedon Mar 9, 2022
Just to point out that serving single file with
e.Staticmay not be that secure ase.Statictakes everything from URL after your prefix (this case prefix =""and uses it as suffix to your root (in this case./index.html)So if you have
and for some odd reason that
index.htmlis not a file but folder instead. We can download files from that folder by appending file name to request.with
heat1q commentedon Mar 10, 2022
Thanks for clarifying! I'll definitely use
e.Filefor serving single files from now on.Edit:
I just noticed when using the
e.Filemethod and appending the current directory to the path, it also seems to show different behaviour:is working with
v4.6.3but returns a404 Not foundwithv4.7.0.lammel commentedon Mar 14, 2022
@heat1q The edge case should be fixed in v4.7.1.
Could you please verify and close this issue. Thnx.
heat1q commentedon Mar 14, 2022
It's working now as expected. Thanks a lot!