aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author65432021-03-23 19:45:06 +0100
committerGitHub2021-03-23 18:45:06 +0000
commit151bedab524a0844758d48bcab5b44a099976c23 (patch)
treed516515e75bda6b5d7ea0342350192b2d1b5360d
parent6198403fbc4e6d2ba497eecd54b113a7752399b2 (diff)
Fix bug on avatar middleware (#15125)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r--routers/routes/routes.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/routers/routes/routes.go b/routers/routes/routes.go
index bdde8216c..78468476e 100644
--- a/routers/routes/routes.go
+++ b/routers/routes/routes.go
@@ -13,6 +13,7 @@ import (
"net/http"
"os"
"path"
+ "path/filepath"
"strings"
"text/template"
"time"
@@ -152,12 +153,21 @@ func storageHandler(storageSetting setting.Storage, prefix string, objStore stor
return
}
- if !strings.HasPrefix(req.URL.RequestURI(), "/"+prefix) {
+ prefix := strings.Trim(prefix, "/")
+
+ if !strings.HasPrefix(req.URL.EscapedPath(), "/"+prefix+"/") {
return
}
+ rPath := strings.TrimPrefix(req.URL.EscapedPath(), "/"+prefix+"/")
- rPath := strings.TrimPrefix(req.URL.RequestURI(), "/"+prefix)
rPath = strings.TrimPrefix(rPath, "/")
+ if rPath == "" {
+ ctx.Error(404, "file not found")
+ return
+ }
+ rPath = path.Clean("/" + filepath.ToSlash(rPath))
+ rPath = rPath[1:]
+
//If we have matched and access to release or issue
fr, err := objStore.Open(rPath)
if err != nil {