1
0
Fork 0
mirror of https://github.com/Luzifer/preserve.git synced 2024-12-20 09:41:18 +00:00

Fix: decode b64 URIs before generating cache path

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2021-11-05 16:16:22 +01:00
parent 4206f2719d
commit 262d5798c9
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

18
main.go
View file

@ -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