Disable Directory Listings

This commit is contained in:
visionmercer 2026-04-15 10:49:26 +02:00
commit 823ce084e3
3 changed files with 27 additions and 1 deletions

View file

@ -209,7 +209,32 @@ func (h *Handler) RawFile(w http.ResponseWriter, r *http.Request) {
}
func (h *Handler) ServeStatic(w http.ResponseWriter, r *http.Request) {
http.StripPrefix("/static/", http.FileServer(h.staticFS)).ServeHTTP(w, r)
// Serve static files with directory listing completely disabled
filePath := strings.TrimPrefix(r.URL.Path, "/static/")
if filePath == "" || strings.HasSuffix(filePath, "/") || strings.Contains(filePath, "..") {
http.NotFound(w, r)
return
}
f, err := h.staticFS.Open(filePath)
if err != nil {
http.NotFound(w, r)
return
}
defer f.Close()
stat, err := f.Stat()
if err != nil {
http.NotFound(w, r)
return
}
if stat.IsDir() {
http.NotFound(w, r)
return
}
http.ServeContent(w, r, stat.Name(), stat.ModTime(), f)
}
func (h *Handler) openISO(relPath string) (*iso.Reader, error) {

0
test_secure/test.iso Normal file
View file

1
test_secure/test.txt Normal file
View file

@ -0,0 +1 @@
Test