mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-19 06:19:27 +00:00
node: normalize HTTP vhost host matching (#34693)
This commit is contained in:
parent
8a0223e8da
commit
d4027f3d46
2 changed files with 4 additions and 0 deletions
|
|
@ -463,6 +463,7 @@ func (h *virtualHostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
// Either invalid (too many colons) or no port specified
|
// Either invalid (too many colons) or no port specified
|
||||||
host = r.Host
|
host = r.Host
|
||||||
}
|
}
|
||||||
|
host = strings.ToLower(host)
|
||||||
if ipAddr := net.ParseIP(host); ipAddr != nil {
|
if ipAddr := net.ParseIP(host); ipAddr != nil {
|
||||||
// It's an IP address, we can serve that
|
// It's an IP address, we can serve that
|
||||||
h.next.ServeHTTP(w, r)
|
h.next.ServeHTTP(w, r)
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,9 @@ func TestVhosts(t *testing.T) {
|
||||||
resp := rpcRequest(t, url, testMethod, "host", "test")
|
resp := rpcRequest(t, url, testMethod, "host", "test")
|
||||||
assert.Equal(t, resp.StatusCode, http.StatusOK)
|
assert.Equal(t, resp.StatusCode, http.StatusOK)
|
||||||
|
|
||||||
|
respUpper := rpcRequest(t, url, testMethod, "host", "TeSt:1234")
|
||||||
|
assert.Equal(t, respUpper.StatusCode, http.StatusOK)
|
||||||
|
|
||||||
resp2 := rpcRequest(t, url, testMethod, "host", "bad")
|
resp2 := rpcRequest(t, url, testMethod, "host", "bad")
|
||||||
assert.Equal(t, resp2.StatusCode, http.StatusForbidden)
|
assert.Equal(t, resp2.StatusCode, http.StatusForbidden)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue