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 1/5] 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 From ef3792449356bbfad2b66708fc39cfbc5a53d62e Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Thu, 2 Jan 2025 08:21:01 -1000 Subject: [PATCH 2/5] Test against different gateway-conformance test version --- .github/workflows/gateway-conformance.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/gateway-conformance.yml b/.github/workflows/gateway-conformance.yml index a6c1b6c6e..fcac54ad9 100644 --- a/.github/workflows/gateway-conformance.yml +++ b/.github/workflows/gateway-conformance.yml @@ -22,7 +22,7 @@ jobs: steps: # 1. Download the gateway-conformance fixtures - name: Download gateway-conformance fixtures - uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@v0.6 + uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@8f8898bc621b64ebe8570a992778c2ac0718fe36 with: output: fixtures merged: true @@ -47,7 +47,7 @@ jobs: # 4. Run the gateway-conformance tests - name: Run gateway-conformance tests - uses: ipfs/gateway-conformance/.github/actions/test@v0.6 + uses: ipfs/gateway-conformance/.github/actions/test@8f8898bc621b64ebe8570a992778c2ac0718fe36 with: gateway-url: http://127.0.0.1:8040 subdomain-url: http://example.net:8040 @@ -84,7 +84,7 @@ jobs: steps: # 1. Download the gateway-conformance fixtures - name: Download gateway-conformance fixtures - uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@v0.6 + uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@8f8898bc621b64ebe8570a992778c2ac0718fe36 with: output: fixtures merged: true @@ -114,7 +114,7 @@ jobs: # 4. Run the gateway-conformance tests - name: Run gateway-conformance tests - uses: ipfs/gateway-conformance/.github/actions/test@v0.6 + uses: ipfs/gateway-conformance/.github/actions/test@8f8898bc621b64ebe8570a992778c2ac0718fe36 with: gateway-url: http://127.0.0.1:8040 # we test gateway that is backed by a remote block gateway subdomain-url: http://example.net:8040 @@ -152,7 +152,7 @@ jobs: steps: # 1. Download the gateway-conformance fixtures - name: Download gateway-conformance fixtures - uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@v0.6 + uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@8f8898bc621b64ebe8570a992778c2ac0718fe36 with: output: fixtures merged: true @@ -182,7 +182,7 @@ jobs: # 4. Run the gateway-conformance tests - name: Run gateway-conformance tests - uses: ipfs/gateway-conformance/.github/actions/test@v0.6 + uses: ipfs/gateway-conformance/.github/actions/test@8f8898bc621b64ebe8570a992778c2ac0718fe36 with: gateway-url: http://127.0.0.1:8040 # we test gateway that is backed by a remote car gateway subdomain-url: http://example.net:8040 From 03a7e96bfc931f7a67e5224cdd2a4ac3a2809d34 Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Thu, 2 Jan 2025 08:25:32 -1000 Subject: [PATCH 3/5] update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e98e6dd57..fa46c5b84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ 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) +- `gateway` Fix redirect URLs for subdirectories with characters that need escaping. [#779](https://github.com/ipfs/boxo/pull/779) ### Security From 7b7a384df74589b947b8f2bb033effc2cb373286 Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Thu, 2 Jan 2025 08:50:18 -1000 Subject: [PATCH 4/5] Use gateway-sharness from kubo PR --- .github/workflows/gateway-sharness.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/gateway-sharness.yml b/.github/workflows/gateway-sharness.yml index a2058126e..c3f1895b8 100644 --- a/.github/workflows/gateway-sharness.yml +++ b/.github/workflows/gateway-sharness.yml @@ -28,6 +28,7 @@ jobs: with: repository: ipfs/kubo path: kubo + ref: fix-gateway-percent-in-dirname - name: Install Missing Tools run: sudo apt install -y socat net-tools fish libxml2-utils - name: Replace boxo in Kubo go.mod From 00b43865d4587d5c07b2cb9e252713169b01f67b Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Fri, 3 Jan 2025 10:17:53 -1000 Subject: [PATCH 5/5] Update to latest gateway-conformance version --- .github/workflows/gateway-conformance.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/gateway-conformance.yml b/.github/workflows/gateway-conformance.yml index fcac54ad9..60a2cfc18 100644 --- a/.github/workflows/gateway-conformance.yml +++ b/.github/workflows/gateway-conformance.yml @@ -22,7 +22,7 @@ jobs: steps: # 1. Download the gateway-conformance fixtures - name: Download gateway-conformance fixtures - uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@8f8898bc621b64ebe8570a992778c2ac0718fe36 + uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@v0.7 with: output: fixtures merged: true @@ -47,7 +47,7 @@ jobs: # 4. Run the gateway-conformance tests - name: Run gateway-conformance tests - uses: ipfs/gateway-conformance/.github/actions/test@8f8898bc621b64ebe8570a992778c2ac0718fe36 + uses: ipfs/gateway-conformance/.github/actions/test@v0.7 with: gateway-url: http://127.0.0.1:8040 subdomain-url: http://example.net:8040 @@ -84,7 +84,7 @@ jobs: steps: # 1. Download the gateway-conformance fixtures - name: Download gateway-conformance fixtures - uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@8f8898bc621b64ebe8570a992778c2ac0718fe36 + uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@v0.7 with: output: fixtures merged: true @@ -114,7 +114,7 @@ jobs: # 4. Run the gateway-conformance tests - name: Run gateway-conformance tests - uses: ipfs/gateway-conformance/.github/actions/test@8f8898bc621b64ebe8570a992778c2ac0718fe36 + uses: ipfs/gateway-conformance/.github/actions/test@v0.7 with: gateway-url: http://127.0.0.1:8040 # we test gateway that is backed by a remote block gateway subdomain-url: http://example.net:8040 @@ -152,7 +152,7 @@ jobs: steps: # 1. Download the gateway-conformance fixtures - name: Download gateway-conformance fixtures - uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@8f8898bc621b64ebe8570a992778c2ac0718fe36 + uses: ipfs/gateway-conformance/.github/actions/extract-fixtures@v0.7 with: output: fixtures merged: true @@ -182,7 +182,7 @@ jobs: # 4. Run the gateway-conformance tests - name: Run gateway-conformance tests - uses: ipfs/gateway-conformance/.github/actions/test@8f8898bc621b64ebe8570a992778c2ac0718fe36 + uses: ipfs/gateway-conformance/.github/actions/test@v0.7 with: gateway-url: http://127.0.0.1:8040 # we test gateway that is backed by a remote car gateway subdomain-url: http://example.net:8040