fix: clean path in createStaticHandler before opening file (#4451)

This commit is contained in:
water 2026-07-31 23:59:37 +08:00
parent 34dac209ff
commit 00a07adccf

View File

@ -223,6 +223,10 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS
}
file := c.Param("filepath")
// Clean the path to handle trailing slashes and invalid paths.
// Many fs.FS implementations (e.g. fs.Sub, http.FS) reject paths with
// trailing slashes because fs.ValidPath considers them invalid.
file = path.Clean(file)
// Check if file exists and/or if we have permission to access it
f, err := fs.Open(file)
if err != nil {