Skip to content

Commit

Permalink
fix/gateway: escape directory redirect url (#779)
Browse files Browse the repository at this point in the history
* 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 ipfs/kubo#10536

* Test against new gateway-conformance test version
  • Loading branch information
gammazero authored Jan 3, 2025
1 parent 85fbc3a commit 5810fed
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/gateway-conformance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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@v0.7
with:
output: fixtures
merged: true
Expand All @@ -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@v0.7
with:
gateway-url: http://127.0.0.1:8040
subdomain-url: http://example.net:8040
Expand Down Expand Up @@ -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@v0.7
with:
output: fixtures
merged: true
Expand Down Expand Up @@ -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@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
Expand Down Expand Up @@ -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@v0.7
with:
output: fixtures
merged: true
Expand Down Expand Up @@ -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@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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/gateway-sharness.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ The following emojis are used to highlight certain changes:

### Fixed

- `gateway` Fix redirect URLs for subdirectories with characters that need escaping. [#779](https://github.com/ipfs/boxo/pull/779)

### Security


Expand Down
2 changes: 1 addition & 1 deletion gateway/handler_unixfs_dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5810fed

Please sign in to comment.