diff options
author | 6543 | 2021-03-23 19:45:06 +0100 |
---|---|---|
committer | GitHub | 2021-03-23 18:45:06 +0000 |
commit | 151bedab524a0844758d48bcab5b44a099976c23 (patch) | |
tree | d516515e75bda6b5d7ea0342350192b2d1b5360d | |
parent | 6198403fbc4e6d2ba497eecd54b113a7752399b2 (diff) |
Fix bug on avatar middleware (#15125)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
-rw-r--r-- | routers/routes/routes.go | 14 |
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 { |