From 5da1972d1f13fae5bd1ddc196046d03996918695 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Sun, 21 Feb 2016 22:38:38 -0800 Subject: [PATCH] router: Fix "/minio" router for web. --- generic-handlers.go | 15 ++++++--------- routers.go | 4 ++-- web-handlers.go | 3 ++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/generic-handlers.go b/generic-handlers.go index 8d8f96d84..bef152e52 100644 --- a/generic-handlers.go +++ b/generic-handlers.go @@ -20,7 +20,6 @@ import ( "errors" "net/http" "path" - "path/filepath" "strings" "time" @@ -30,7 +29,7 @@ import ( const ( iso8601Format = "20060102T150405Z" - privateBucket = "minio" + privateBucket = "/minio" ) // HandlerFunc - useful to chain different middleware http.Handler @@ -101,14 +100,12 @@ func setBrowserRedirectHandler(h http.Handler) http.Handler { func (h redirectHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Re-direction handled specifically for browsers. if strings.Contains(r.Header.Get("User-Agent"), "Mozilla") { - // Following re-direction code handles redirects only for - // these specific incoming URLs. - // '/' is redirected to '/locationPrefix' - // '/rpc' is redirected to '/locationPrefix/rpc' - // '/login' is redirected to '/locationPrefix/login' + // '/' is redirected to 'locationPrefix/' + // '/rpc' is redirected to 'locationPrefix/rpc' + // '/login' is redirected to 'locationPrefix/login' switch r.URL.Path { case "/", "/rpc", "/login": - location := path.Join(h.locationPrefix, r.URL.Path) + location := h.locationPrefix + r.URL.Path // Redirect to new location. http.Redirect(w, r, location, http.StatusTemporaryRedirect) return @@ -146,7 +143,7 @@ func setPrivateBucketHandler(h http.Handler) http.Handler { func (h minioPrivateBucketHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // For all non browser requests, reject access to 'privateBucket'. - if !strings.Contains(r.Header.Get("User-Agent"), "Mozilla") && filepath.Base(r.URL.Path) == privateBucket { + if !strings.Contains(r.Header.Get("User-Agent"), "Mozilla") && path.Clean(r.URL.Path) == privateBucket { writeErrorResponse(w, r, AllAccessDisabled, r.URL.Path) return } diff --git a/routers.go b/routers.go index 496396d36..debda527a 100644 --- a/routers.go +++ b/routers.go @@ -19,7 +19,7 @@ package main import ( "net" "net/http" - "path/filepath" + "path" router "github.com/gorilla/mux" jsonrpc "github.com/gorilla/rpc/v2" @@ -74,7 +74,7 @@ func registerAPIHandlers(mux *router.Router, a storageAPI, w *webAPI) { minio.Path("/rpc").Handler(rpc) // Web handler assets at URI - /minio/login - minio.Path("/login").Handler(http.StripPrefix(filepath.Join(privateBucket, "login"), http.FileServer(assetFS()))) + minio.Path("/login").Handler(http.StripPrefix(path.Join(privateBucket, "login"), http.FileServer(assetFS()))) minio.Path("/{file:.*}").Handler(http.StripPrefix(privateBucket, http.FileServer(assetFS()))) // API Router diff --git a/web-handlers.go b/web-handlers.go index 41d08be4c..9227301e6 100644 --- a/web-handlers.go +++ b/web-handlers.go @@ -21,6 +21,7 @@ import ( "net/http" "net/url" "os" + "path" "path/filepath" "runtime" "strconv" @@ -175,7 +176,7 @@ func (web *webAPI) ListBuckets(r *http.Request, args *ListBucketsArgs, reply *Li } for _, bucket := range buckets { // List all buckets which are not private. - if bucket.Name != privateBucket { + if bucket.Name != path.Base(privateBucket) { reply.Buckets = append(reply.Buckets, BucketInfo{ Name: bucket.Name, CreationDate: bucket.CreationDate,