wasihttp: P2 Transport sends an empty authority on redirects (uses req.Host, not req.URL.Host)
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 76/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- go
- 領域
- backend, networking
調査の方向性
Read wasihttp/roundtripper_p2.go around the authority and path construction, then compare it with wasihttp/roundtripper_p3.go and the redirect request construction in net/http/client.go cited in the issue. Check how Go represents the URL host, request URI, and custom Host value. Done means redirects send the URL authority and preserve the encoded path and query, while a differing Host value returns a clear error.
索引モデルが issue の本文から書いたものです。
説明
The P2 Transport in wasihttp sets the outgoing request's authority from req.Host. net/http leaves Host empty on the request it builds for a redirect, so every redirect goes out with an empty authority and fails. On Spin 4.3.0 the second hop comes back as HTTP-request-URI-invalid:
GET http://127.0.0.1:18081/final -> 200
GET http://127.0.0.1:18081/redirect (302 to /final)
ERR: Get "http://127.0.0.1:18081/final": failed to acquire handle to outbound request: {19 <nil>}
The origin never sees the second request. The first hop works only because http.NewRequestWithContext copies u.Host into req.Host (net/http/request.go:931). The redirect request is built in client.go (~655-683) as &Request{..., URL: u, Host: host}, where host is "" unless the caller set a custom Host and the Location is relative.
The relevant lines are in wasihttp/roundtripper_p2.go (same in v0.1.2 and main at d97e278):
outRequest.SetAuthority(witTypes.Some(incomingRequest.Host)) // :60
pathWithQuery := incomingRequest.URL.Path // :63
if incomingRequest.URL.RawQuery != "" {
pathWithQuery = pathWithQuery + "?" + incomingRequest.URL.Query().Encode() // :65
}
Two smaller problems on the same lines:
URL.Pathis the decoded path, so/a%2Fbis sent as/a/b.URL.Query().Encode()re-sorts and re-encodes the query (?z=1&a=2goes out as?a=2&z=1), which breaks signed URLs.
When req.Host is set to something other than URL.Host, it becomes the authority. The request is then checked against the host's allow-list, and connected, as that other name, not the host in the URL. net/http would send it as a Host header instead, but Host is a forbidden header on wasi:http (setting it fails with header-error 1). So I don't think there's a correct way to honour a differing req.Host here.
The P3 roundtripper already gets the path right (req.URL.RequestURI()), and falls back to URL.Host when Host is empty (roundtripper_p3.go:129-134). It still lets a non-empty req.Host override the authority, though.
Suggested fix (P2, and the precedence in P3):
- take the authority from
req.URL.Host, and return an error if it's empty; - return an error if
req.Hostis set and differs fromreq.URL.Host(case-insensitive); - use
req.URL.RequestURI()for the path and query; - keep leaving redirects to
http.Client, so the host re-checks every hop.
We're carrying exactly this in a vendored copy for a Go sandbox on Spin. A same-host redirect now returns 200, %2F and the query arrive unchanged, and a Host mismatch gives a clear error: https://github.com/mastersingh24/spin-code-sandbox/blob/8d85b45a5a9bb8659e282d616b9c4e49f67dac52/experiments/go-sandbox/guest/wasihttpc/roundtripper_p2.go
Happy to send a PR if this direction looks right.
Repro setup: Spin 4.3.0, go1.27.4, componentize-go 0.5.4, unmodified go.bytecodealliance.org/wasi v0.1.2, allowed_outbound_hosts = ["http://127.0.0.1:18081"], and a local origin where /redirect returns 302 Location: /final.
- 主要言語
- Go
- スター
- 2
- フォーク
- 3
- 平均マージ
- 14時間 12分
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
似ている issue
-
Linux 主机 macOS 主机
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
Lee-xeo/Claude-Cage#1455 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
slavakurilyak/awesome-ai-agents#1137 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
-
Make the HTTP server's keep-alive and headers timeouts configurable対応中かも @mattgodbolt が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
compiler-explorer/compiler-explorer#9902 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信