diff options
author | Filip Aleksic <faleksic@gitlab.com> | 2022-07-26 10:53:41 +0300 |
---|---|---|
committer | Jaime Martinez <jmartinez@gitlab.com> | 2022-07-26 10:53:41 +0300 |
commit | a131f2bdf10e2815d79e3581fe6536b1499839b6 (patch) | |
tree | 723189f5398744b7e5a0e260835a0c38f84f2f66 /internal/redirects | |
parent | 0674de2e8e74a35bec70380b02da63dd7db1b8bb (diff) |
Fixes acme redirection issues when using a wildcard redirect
Changelog: fixed
Diffstat (limited to 'internal/redirects')
-rw-r--r-- | internal/redirects/redirects.go | 5 | ||||
-rw-r--r-- | internal/redirects/redirects_test.go | 8 |
2 files changed, 13 insertions, 0 deletions
diff --git a/internal/redirects/redirects.go b/internal/redirects/redirects.go index 4add6537..4903518a 100644 --- a/internal/redirects/redirects.go +++ b/internal/redirects/redirects.go @@ -13,6 +13,7 @@ import ( netlifyRedirects "github.com/tj/go-redirects" "gitlab.com/gitlab-org/labkit/log" + "gitlab.com/gitlab-org/gitlab-pages/internal/acme" "gitlab.com/gitlab-org/gitlab-pages/internal/config" "gitlab.com/gitlab-org/gitlab-pages/internal/vfs" ) @@ -106,6 +107,10 @@ func (r *Redirects) Status() string { // Rewrite takes in a URL and uses the parsed Netlify rules to rewrite // the URL to the new location if it matches any rule func (r *Redirects) Rewrite(originalURL *url.URL) (*url.URL, int, error) { + if acme.IsAcmeChallenge(originalURL.Path) { + return nil, 0, ErrNoRedirect + } + rule, newPath := r.match(originalURL.Path) if rule == nil { return nil, 0, ErrNoRedirect diff --git a/internal/redirects/redirects_test.go b/internal/redirects/redirects_test.go index d40b065b..4ec34222 100644 --- a/internal/redirects/redirects_test.go +++ b/internal/redirects/redirects_test.go @@ -107,6 +107,14 @@ func TestRedirectsRewrite(t *testing.T) { expectedURL: "/the/cake/is/a/lie", expectedStatus: http.StatusOK, }, + { + name: "does_not_redirect_acme_challenges", + url: "/.well-known/acme-challenge/token", + rule: "/* /to/path 200", + expectedURL: "", + expectedStatus: 0, + expectedErr: ErrNoRedirect, + }, } for _, tt := range tests { |