diff options
author | Jaime Martinez <jmartinez@gitlab.com> | 2020-09-21 10:31:22 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2020-09-24 03:22:45 +0300 |
commit | 228376ae7c12d10c1e15486b9077cbcc898bc769 (patch) | |
tree | f5717c5208b09f6d98ea5aefba27284605c0883e | |
parent | ec0553079f31cd244298353589a9c84ccf8c82d2 (diff) |
Restore prefix validation
-rw-r--r-- | internal/source/gitlab/factory.go | 4 | ||||
-rw-r--r-- | internal/source/gitlab/gitlab.go | 12 | ||||
-rw-r--r-- | internal/vfs/zip/vfs.go | 8 |
3 files changed, 10 insertions, 14 deletions
diff --git a/internal/source/gitlab/factory.go b/internal/source/gitlab/factory.go index 39193a16..149b3595 100644 --- a/internal/source/gitlab/factory.go +++ b/internal/source/gitlab/factory.go @@ -1,6 +1,8 @@ package gitlab import ( + "strings" + log "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitlab-pages/internal/serving" @@ -16,7 +18,7 @@ import ( func fabricateLookupPath(size int, lookup api.LookupPath) *serving.LookupPath { return &serving.LookupPath{ Prefix: lookup.Prefix, - Path: lookup.Source.Path, + Path: strings.TrimPrefix(lookup.Source.Path, "/"), IsNamespaceProject: (lookup.Prefix == "/" && size > 1), IsHTTPSOnly: lookup.HTTPSOnly, HasAccessControl: lookup.AccessControl, diff --git a/internal/source/gitlab/gitlab.go b/internal/source/gitlab/gitlab.go index fb15a07a..67c4eb6b 100644 --- a/internal/source/gitlab/gitlab.go +++ b/internal/source/gitlab/gitlab.go @@ -4,7 +4,6 @@ import ( "context" "errors" "net/http" - "net/url" "path" "strings" "sync" @@ -95,17 +94,6 @@ func (g *Gitlab) Resolve(r *http.Request) (*serving.Request, error) { subPath = strings.TrimPrefix(urlPath, lookup.Prefix) } - if lookup.Source.Type == "zip" { - urlPath, err := url.Parse(lookup.Source.Path) - if err != nil { - return nil, err - } - - lookup.Source.Path = urlPath.String() - } else { - lookup.Source.Path = strings.TrimPrefix(lookup.Source.Path, "/") - } - return &serving.Request{ Serving: fabricateServing(lookup), LookupPath: fabricateLookupPath(size, lookup), diff --git a/internal/vfs/zip/vfs.go b/internal/vfs/zip/vfs.go index b3d4429b..d4e9cc60 100644 --- a/internal/vfs/zip/vfs.go +++ b/internal/vfs/zip/vfs.go @@ -3,6 +3,7 @@ package zip import ( "context" "errors" + "net/url" "time" "github.com/patrickmn/go-cache" @@ -44,9 +45,14 @@ func New(name string) vfs.VFS { // to try and find the cached archive or return if there's an error, for example // if the context is canceled. func (fs *zipVFS) Root(ctx context.Context, path string) (vfs.Root, error) { + urlPath, err := url.Parse(path) + if err != nil { + return nil, err + } + // we do it in loop to not use any additional locks for { - root, err := fs.findOrOpenArchive(ctx, path) + root, err := fs.findOrOpenArchive(ctx, urlPath.String()) if err == errAlreadyCached { continue } |