From 6376bfd2e0e0b64744731aaa8519c1c19fd04853 Mon Sep 17 00:00:00 2001 From: crapStone Date: Sun, 29 Dec 2024 19:01:08 +0000 Subject: [PATCH] Fix stack overflow on root redirects (#414) Reviewed-on: https://codeberg.org/Codeberg/pages-server/pulls/414 Co-authored-by: crapStone Co-committed-by: crapStone --- server/upstream/redirects.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/server/upstream/redirects.go b/server/upstream/redirects.go index 3ed5010..b0762d5 100644 --- a/server/upstream/redirects.go +++ b/server/upstream/redirects.go @@ -92,8 +92,9 @@ func (o *Options) matchRedirects(ctx *context.Context, giteaClient *gitea.Client for _, redirect := range redirects { if dstURL, ok := redirect.rewriteURL(reqURL); ok { - // do rewrite if status code is 200 - if redirect.StatusCode == 200 { + if o.TargetPath == dstURL { // recursion base case, rewrite directly when paths are the same + return true + } else if redirect.StatusCode == 200 { // do rewrite if status code is 200 o.TargetPath = dstURL o.Upstream(ctx, giteaClient, redirectsCache) } else {