From 8328d1cb11cdba28fb7ffdb87fe5a43093daf212 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sun, 27 Dec 2020 15:41:21 -0800 Subject: [PATCH] Disable serving a directory listing. Closes #530 --- controllers/index.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/controllers/index.go b/controllers/index.go index e340bc6c1..058ef121f 100644 --- a/controllers/index.go +++ b/controllers/index.go @@ -4,6 +4,7 @@ import ( "fmt" "net/http" "net/url" + "os" "path" "path/filepath" "strings" @@ -43,6 +44,13 @@ func IndexHandler(w http.ResponseWriter, r *http.Request) { return } + // If this is a directory listing request then return a 404 + info, err := os.Stat(path.Join(config.WebRoot, r.URL.Path)) + if err != nil || (info.IsDir() && !isIndexRequest) { + w.WriteHeader(http.StatusNotFound) + return + } + if path.Ext(r.URL.Path) == ".m3u8" { middleware.DisableCache(w) }