Compare commits

...

3 Commits

Author SHA1 Message Date
Ruben Pari
53745e8bf5
Merge d7d24601340cfbfebb52c5eeb15bd689ff5a0276 into 3b08cd7235bd5ad2f055aa9e38135f111f6c5926 2026-09-20 13:08:36 +00:00
RubenPari
d7d2460134 merge: update master for CI security and coverage baseline
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-20 15:07:31 +02:00
RubenPari
0714c8e198 fix(router): clean StaticFS paths before fs.Open
Preflight Open used the raw filepath param, so trailing-slash
directory URLs failed ValidPath on embed/fs.FS before FileServer
could clean. Match net/http.FileServer with path.Clean("/"+...).

Fixes #4451
2026-08-08 09:58:34 +02:00
2 changed files with 21 additions and 1 deletions

View File

@ -262,7 +262,9 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS
c.Writer.WriteHeader(http.StatusNotFound)
}
file := c.Param("filepath")
// Normalize like net/http.FileServer so embed/fs.Sub preflight Open
// accepts directory URLs with trailing slashes (#4451).
file := path.Clean("/" + c.Param("filepath"))
// Check if file exists and/or if we have permission to access it
f, err := fs.Open(file)
if err != nil {

View File

@ -12,6 +12,7 @@ import (
"path/filepath"
"strings"
"testing"
"testing/fstest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@ -701,6 +702,23 @@ func TestRouterStaticFSNotFound(t *testing.T) {
assert.Equal(t, "non existent", w.Body.String())
}
func TestRouterStaticFSTrailingSlashEmbed(t *testing.T) {
fsys := fstest.MapFS{
"dir/index.html": &fstest.MapFile{Data: []byte("INDEX")},
"dir/file.txt": &fstest.MapFile{Data: []byte("FILE")},
}
router := New()
router.StaticFS("/static", http.FS(fsys))
w := PerformRequest(router, http.MethodGet, "/static/dir/")
assert.Equal(t, http.StatusOK, w.Code)
assert.Contains(t, w.Body.String(), "INDEX")
w = PerformRequest(router, http.MethodGet, "/static/dir/file.txt")
assert.Equal(t, http.StatusOK, w.Code)
assert.Equal(t, "FILE", w.Body.String())
}
func TestRouterStaticFSFileNotFound(t *testing.T) {
router := New()