From 262d5798c9450fc47467be9f12b057969fb9b98c Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Fri, 5 Nov 2021 16:16:22 +0100 Subject: [PATCH] Fix: decode b64 URIs before generating cache path Signed-off-by: Knut Ahlers --- main.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/main.go b/main.go index 2099ee2..14422fd 100644 --- a/main.go +++ b/main.go @@ -91,15 +91,6 @@ func handleCacheOnce(w http.ResponseWriter, r *http.Request) { } func handleCache(w http.ResponseWriter, r *http.Request, uri string, update bool) { - var ( - cachePath = urlToCachePath(uri) - cacheHeader = "HIT" - logger = log.WithFields(log.Fields{ - "url": uri, - "path": cachePath, - }) - ) - if strings.HasPrefix(uri, "b64:") { u, err := base64.URLEncoding.DecodeString(strings.TrimPrefix(uri, "b64:")) if err != nil { @@ -109,6 +100,15 @@ func handleCache(w http.ResponseWriter, r *http.Request, uri string, update bool uri = string(u) } + var ( + cachePath = urlToCachePath(uri) + cacheHeader = "HIT" + logger = log.WithFields(log.Fields{ + "url": uri, + "path": cachePath, + }) + ) + if u, err := url.Parse(uri); err != nil || u.Scheme == "" { http.Error(w, "Unable to parse requested URL", http.StatusBadRequest) return