Sample
net/http go1.26.5: Prove that net/http keeps the Authorization header stripped through the full redirect chain after a cross-domain hop, and does not restore it on a subsequent same-domain redirect (CVE-2024-45336).
Verified sample for golang net/http go1.26.5: Prove that net/http keeps the Authorization header stripped through the full redirect chain after a…
sha256:ca2c5fb0a4c0366c9e1e2ca07cd75ca1c776ff2e9eab90fc258851b1d37fefe6
This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured.
How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people.
MIT-0
Execution evidence
The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.
- Evidence basis
- Signed contract pass
- Verification receipts
- 2
- Signing keys that built it
- 2
Declared environment
go linux x64 go go gomod
Verification-run environments
| Environment | Contract | Stages | Run |
|---|---|---|---|
| go 1.26 · linux alpine/x64 · docker ed25519:d91480838ac982c9 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-16 |
| go 1.26 · linux alpine/x64 · docker ed25519:2175b912ea1c23b1 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1 |
2026-08-18 |
Case
HOW- Goal
- Prove that net/http keeps the Authorization header stripped through the full redirect chain after a cross-domain hop, and does not restore it on a subsequent same-domain redirect (CVE-2024-45336).
- Packages
- Symbols
-
- http.Client
- http.Client.Do
- shouldCopyHeaderOnRedirect
- Environment
- go
- Created
- 2026-08-16T14:53:27Z
Contract
- After a three-hop redirect chain where the first cross-domain hop strips Authorization, the Authorization header must be absent at the same-domain second hop on serverB — before go1.23.7 / go1.24.1 this assertion fails silently with a 200 response.
- net/http does not restore Authorization on a same-domain redirect that follows a cross-domain redirect.
Files
- NOTES.md
- csx.json
- go.mod
- redirect_header_test.go
Source
# net/http redirect header stripping across a multi-hop chain
## What search_known_solution found
The search returned two existing samples (both COMPATIBLE / LOW confidence):
- **`sha256:a5d71...`** — shows that `http.Client.Timeout` is enforced while reading a slow response body.
- **`sha256:e5f8c...`** (PUBLISHED) — proves that `http.Client` rewrites a POST to GET when automatically following a 303 response.
Neither covers multi-hop redirect header stripping. This sample was written to fill that gap.
## The trap
`net/http` strips sensitive headers (`Authorization`, `Cookie`, …) when following a cross-domain redirect. A competent developer — and most models — assume that once the header is stripped it stays stripped. Before **go1.23.7 / go1.24.1** that assumption was wrong.
The internal helper `shouldCopyHeaderOnRedirect` was called on every redirect hop by comparing the *previous* hop's URL against the *current* destination. When the chain was:
```
[::1] → 127.0.0.1/step1 → 127.0.0.1/step2
```
the first hop (`[::1]` → `127.0.0.1`) correctly stripped `Authorization`. The second hop (`127.0.0.1/step1` → `127.0.0.1/step2`) compared the *previous* URL (`127.0.0.1`) against the destination (`127.0.0.1`) — same host — so the header was **silently restored** and sent to `127.0.0.1/step2`.
The fix (CVE-2024-45336) changed the comparison to always use the *initial* request URL (`[::1]`) against the destination. Once the flag `stripSensitiveHeaders` is set to `true` for any hop, the updated code guards against re-evaluation with `if !stripSensitiveHeaders`, so it can never be reversed.
## How the wrong version fails
**Silently, with a green build.**
The server at `127.0.0.1/step2` receives `Authorization: Bearer …` and responds with `200 OK`. No error is returned. No redirect fails. `client.Do` returns `nil` error. The only way to detect the leak is an explicit assertion on what the destination server actually received — which is exactly what the contract here does.
## Key implementation detail
`shouldCopyHeaderOnRedirect` strips the port before comparing hosts (it calls `url.Hostname()`, not the full `url.Host`). Two servers on the *same IP but different ports* (e.g., both on `127.0.0.1`) are treated as the **same domain** and Authorization is forwarded freely. Triggering the CVE therefore requires servers with genuinely different hostnames: this sample uses `[::1]` (IPv6 loopback) for the first server and `127.0.0.1` (IPv4 loopback) for the second.
{"case":{"believed":"Once net/http drops Authorization for a cross-domain redirect, the header stays absent for the rest of the chain — but before go1.23.7 / go1.24.1, a same-domain hop immediately following a cross-domain hop silently restores Authorization to the request, leaking the credential to the second domain while the HTTP response stays 200.","caseId":"case:sha256:c7bcb2a4fc91f31ee1e9a231cac888ab50e30f19d3fbac5de5de900fbfbb242d","contract":["After a three-hop redirect chain where the first cross-domain hop strips Authorization, the Authorization header must be absent at the same-domain second hop on serverB — before go1.23.7 / go1.24.1 this assertion fails silently with a 200 response.","net/http does not restore Authorization on a same-domain redirect that follows a cross-domain redirect."],"goal":"Prove that net/http keeps the Authorization header stripped through the full redirect chain after a cross-domain hop, and does not restore it on a subsequent same-domain redirect (CVE-2024-45336).","kind":"HOW","packages":["pkg:golang/net/http@go1.26.5"],"schemaVersion":1,"symbols":["http.Client","http.Client.Do","shouldCopyHeaderOnRedirect"]},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","ecosystem":"golang","executionContext":"go","language":"go","os":"linux","packageManager":"gomod","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/net/http@go1.26.5"],"schemaVersion":1,"symbols":["http.Client","http.Client.Do","shouldCopyHeaderOnRedirect"],"verifierAdapter":"golang@1"}
module example.test/httpcve
go 1.23
// Package httpcve proves that net/http does NOT restore the Authorization header
// on a same-domain leg that follows a cross-domain redirect
// (CVE-2024-45336, fixed in go1.23.7 / go1.24.1).
//
// Redirect chain:
// serverA ([::1]/start) -- 302 --> serverB (127.0.0.1/step1) [cross-domain: strips Authorization]
// serverB (127.0.0.1/step1) -- 302 --> serverB (127.0.0.1/step2) [same-domain: buggy builds RESTORE Authorization]
// serverB (127.0.0.1/step2) -- 200 --> records Authorization seen
//
// The fix (go1.23.7+ / go1.24.1+) keeps the "strip-sensitive" flag sticky across
// the entire redirect chain. Once a cross-domain hop strips Authorization, it stays
// stripped even on subsequent same-domain hops.
//
// On a buggy build the test assertion FAILS, but the HTTP status is still 200 so CI
// stays green — the credential leak is invisible without an explicit assertion.
package httpcve_test
import (
"net"
"net/http"
"net/http/httptest"
"strings"
"sync"
"testing"
)
// newServerOn starts an httptest.Server bound to a specific address.
func newServerOn(t *testing.T, addr string, h http.Handler) *httptest.Server {
t.Helper()
ln, err := net.Listen("tcp", addr)
if err != nil {
t.Skipf("cannot listen on %s (%v) — skipping test", addr, err)
}
srv := &httptest.Server{Listener: ln, Config: &http.Server{Handler: h}}
srv.Start()
t.Cleanup(srv.Close)
return srv
}
func TestCrossDomainRedirectAuthorizationStaysStripped(t *testing.T) {
var (
mu sync.Mutex
step2AuthHdr string
)
// serverB on IPv4 127.0.0.1 — the "second domain".
// /step1 immediately redirects to /step2 (same-domain hop).
// /step2 records whether Authorization arrived.
serverB := newServerOn(t, "127.0.0.1:0", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/step1":
// Same-domain redirect inside serverB.
// Buggy net/http restores Authorization here because the previous
// hop (serverB/step1) looked same-domain to the current destination
// (serverB/step2).
http.Redirect(w, r, "/step2", http.StatusFound)
case "/step2":
mu.Lock()
step2AuthHdr = r.Header.Get("Authorization")
mu.Unlock()
w.WriteHeader(http.StatusOK)
default:
http.NotFound(w, r)
}
}))
// serverA on IPv6 [::1] — the "first domain", genuinely different from 127.0.0.1.
// net/http's shouldCopyHeaderOnRedirect compares hostnames without ports,
// so "::1" != "127.0.0.1" → cross-domain → Authorization is stripped.
serverA := newServerOn(t, "[::1]:0", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, serverB.URL+"/step1", http.StatusFound)
}))
req, err := http.NewRequest(http.MethodGet, serverA.URL+"/start", nil)
if err != nil {
t.Fatalf("http.NewRequest: %v", err)
}
req.Header.Set("Authorization", "Bearer secret-must-not-reach-serverB")
resp, err := (&http.Client{}).Do(req)
if err != nil {
t.Fatalf("client.Do: %v", err)
}
resp.Body.Close()
mu.Lock()
got := step2AuthHdr
mu.Unlock()
// net/http (fixed) must keep Authorization absent through the entire chain.
// Buggy builds (before go1.23.7 / go1.24.1) send it to /step2, but the
// HTTP response is still 200, so the build stays green — the leak is silent.
if strings.TrimSpace(got) != "" {
t.Errorf(
"Authorization leaked to same-domain leg after cross-domain redirect:\n"+
" got %q\n"+
" want (empty string)\n"+
"CVE-2024-45336 fix not present; requires go1.23.7+ or go1.24.1+",
got,
)
}
}