From 16d89a5a96f0d2cdf35e09120c4fc1f5d6b7da25 Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Wed, 1 Jan 2025 23:47:24 -1000 Subject: [PATCH] Fix redirect for directories to escape special chars in URL Directories with a "%" in their name do not work correctly when when redirected to a URL with a trailing slash. When the original URl contains special characters, such as "%", the correcponding redirect URL must escape these characters. Fixes issue https://github.com/ipfs/kubo/issues/10536 --- CHANGELOG.md | 2 ++ gateway/handler_unixfs_dir.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 199b69066..e98e6dd57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,8 @@ The following emojis are used to highlight certain changes: ### Fixed +- `gateway` Fix links for subdirectories with "%" in name. [#779](https://github.com/ipfs/boxo/pull/779) + ### Security diff --git a/gateway/handler_unixfs_dir.go b/gateway/handler_unixfs_dir.go index 6f9f856d1..0aa54b50b 100644 --- a/gateway/handler_unixfs_dir.go +++ b/gateway/handler_unixfs_dir.go @@ -50,7 +50,7 @@ func (i *handler) serveDirectory(ctx context.Context, w http.ResponseWriter, r * suffix = suffix + "?" + r.URL.RawQuery } // /ipfs/cid/foo?bar must be redirected to /ipfs/cid/foo/?bar - redirectURL := originalURLPath + suffix + redirectURL := requestURI.EscapedPath() + suffix rq.logger.Debugw("directory location moved permanently", "status", http.StatusMovedPermanently) http.Redirect(w, r, redirectURL, http.StatusMovedPermanently) return true