Disable Directory Listings
This commit is contained in:
parent
d1e69723cc
commit
823ce084e3
3 changed files with 27 additions and 1 deletions
|
|
@ -209,7 +209,32 @@ func (h *Handler) RawFile(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *Handler) ServeStatic(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) {
|
func (h *Handler) openISO(relPath string) (*iso.Reader, error) {
|
||||||
|
|
|
||||||
0
test_secure/test.iso
Normal file
0
test_secure/test.iso
Normal file
1
test_secure/test.txt
Normal file
1
test_secure/test.txt
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
Test
|
||||||
Loading…
Add table
Add a link
Reference in a new issue