From 14a8ffedd8d424e39006fb5df62d8af005882f96 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Mon, 27 May 2019 08:12:19 -0600 Subject: [PATCH] Fix panic serving index file if HTTP request is malformed --- caddyhttp/httpserver/middleware.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/caddyhttp/httpserver/middleware.go b/caddyhttp/httpserver/middleware.go index d470811a..dbb44380 100644 --- a/caddyhttp/httpserver/middleware.go +++ b/caddyhttp/httpserver/middleware.go @@ -117,6 +117,10 @@ func (c ConfigSelector) Select(r *http.Request) (config HandlerConfig) { // path separator, just like URLs. IndexFle handles path manipulation // internally for systems that use different path separators. func IndexFile(root http.FileSystem, fpath string, indexFiles []string) (string, bool) { + if len(fpath) == 0 { + // https://caddy.community/t/panic-runtime-error-index-out-of-range/5781 + fpath = "/" + } if fpath[len(fpath)-1] != '/' || root == nil { return "", false }