billingstripe: the write transport offers only HTTP/1.1 by ALPN. It cloned DefaultTransport, whose TLS config offered h2, so Stripe negotiated h2 and every billing POST failed as no response (found in the dev sandbox rehearsal).
Squashed from stripe-write-http1 into main.
3 files changed,
+146
−0
docs/superpowers/reviews/CODEX-REVIEW-BRIEF-stripe-write-http1.md+24 −0internal/billingstripe/client.go+11 −0internal/billingstripe/write_transport_test.go+111 −0
CI passed — run details
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-stripe-write-http1.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-stripe-write-http1.md| new file mode 100644 |
| index 000000000..a0c05c3e1 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-stripe-write-http1.md |
| @@ -0,0 +1,24 @@ |
| +# Review brief: branch stripe-write-http1, round 1 of 3 |
| + |
| +Repo carlos/platform, branch `stripe-write-http1`, the commit that adds this brief (named in your prompt). |
| +Under review: the diff `origin/main...HEAD` (internal/billingstripe/client.go newWriteTransport and a new test file). |
| + |
| +The bug: newWriteTransport cloned http.DefaultTransport, whose TLS config already offered "h2" by ALPN once DefaultTransport had been used, while the transport itself was HTTP/1.1-only (ForceAttemptHTTP2 false, empty TLSNextProto). Stripe negotiated h2 and every billing POST failed with "malformed HTTP response", classified as no response. Reproduced on the dev console against the Stripe sandbox; the fix was confirmed against the real sandbox (a customer create now succeeds through Provider.Send). |
| + |
| +## What to check |
| + |
| +1. The write transport offers only http/1.1 by ALPN, never shares or mutates DefaultTransport's TLS config, and keeps the plan 6b write-path properties: keep-alives off, no automatic resend of a keyed POST (GetBody nil), the same timeouts and redirect refusal. |
| +2. The tests really exercise an h2-capable TLS server through the write path and would fail without the fix; no test leaks global state (DefaultTransport) into others. |
| +3. Anything else in internal/billingstripe that builds a transport or client with the same flaw (the read client, the portal, webhook-related calls). |
| + |
| +## Severity |
| + |
| +- **P1**: unsafe, would not compile, a test fails, or it would not work. Blocks merge. |
| +- **P2**: wrong or missing. Fixed without reopening this review. |
| +- **P3**: clarity or polish. Goes on a follow-up list; never a reason for another round. |
| + |
| +## Output |
| + |
| +Findings ranked P1, P2, P3 with file:line, failure scenario and fix. End with exactly one verdict: **READY**, **READY AFTER FIXES**, or **NOT READY**. |
| + |
| +Do not edit files. Do not spawn Anthropic-model reviewers or subagents of your own. Do not run the full test suites. |
diff --git a/internal/billingstripe/client.go b/internal/billingstripe/client.go| index e60a8699d..78ed6299d 100644 |
| --- a/internal/billingstripe/client.go |
| +++ b/internal/billingstripe/client.go |
| @@ -166,6 +166,17 @@ func newWriteTransport() *http.Transport { |
| t.DisableKeepAlives = true |
| t.ForceAttemptHTTP2 = false |
| t.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{} |
| + // Clone copies DefaultTransport's TLS config, and once DefaultTransport |
| + // has been used (the read client does) its NextProtos hold "h2". With |
| + // that, the handshake offers h2 by ALPN, Stripe picks it, and this |
| + // HTTP/1.x transport reads an HTTP/2 SETTINGS frame as a malformed |
| + // response. Offer HTTP/1.1 only, on a config of our own. |
| + if t.TLSClientConfig != nil { |
| + t.TLSClientConfig = t.TLSClientConfig.Clone() |
| + } else { |
| + t.TLSClientConfig = &tls.Config{} |
| + } |
| + t.TLSClientConfig.NextProtos = []string{"http/1.1"} |
| return t |
| } |
diff --git a/internal/billingstripe/write_transport_test.go b/internal/billingstripe/write_transport_test.go| new file mode 100644 |
| index 000000000..88e437ca9 |
| --- /dev/null |
| +++ b/internal/billingstripe/write_transport_test.go |
| @@ -0,0 +1,111 @@ |
| +package billingstripe |
| + |
| +import ( |
| + "context" |
| + "crypto/x509" |
| + "net/http" |
| + "net/http/httptest" |
| + "reflect" |
| + "testing" |
| +) |
| + |
| +// TestWriteTransport_NegotiatesHTTP11AgainstH2Server pins the production |
| +// failure: a TLS server that speaks h2 picked it by ALPN because the write |
| +// transport (cloned from http.DefaultTransport) still offered it, and the |
| +// HTTP/1.x transport then choked on the server's HTTP/2 SETTINGS frame. |
| +func TestWriteTransport_NegotiatesHTTP11AgainstH2Server(t *testing.T) { |
| + // Make DefaultTransport look as it does in a running process, where |
| + // reads have already used it: its TLS config offers h2. |
| + dt := http.DefaultTransport.(*http.Transport) |
| + if dt.TLSClientConfig == nil || !containsProto(dt.TLSClientConfig.NextProtos, "h2") { |
| + warm := httptest.NewUnstartedServer(http.HandlerFunc(func(http.ResponseWriter, *http.Request) {})) |
| + warm.EnableHTTP2 = true |
| + warm.StartTLS() |
| + defer warm.Close() |
| + pool := x509.NewCertPool() |
| + pool.AddCert(warm.Certificate()) |
| + tr := dt.Clone() |
| + tr.ForceAttemptHTTP2 = true |
| + if tr.TLSClientConfig == nil { |
| + tr.TLSClientConfig = warm.Client().Transport.(*http.Transport).TLSClientConfig.Clone() |
| + } |
| + tr.TLSClientConfig.RootCAs = pool |
| + resp, err := (&http.Client{Transport: tr}).Get(warm.URL) |
| + if err != nil { |
| + t.Fatalf("warm-up request: %v", err) |
| + } |
| + resp.Body.Close() |
| + tr.CloseIdleConnections() |
| + } |
| + |
| + var proto string |
| + srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + proto = r.Proto |
| + w.Header().Set("Content-Type", "application/json") |
| + _, _ = w.Write([]byte(`{"id":"cus_1"}`)) |
| + })) |
| + srv.EnableHTTP2 = true |
| + srv.StartTLS() |
| + defer srv.Close() |
| + |
| + c := testClient(t, srv.URL) |
| + wt := c.writeClient.Transport.(*http.Transport) |
| + if wt.TLSClientConfig == nil { |
| + wt.TLSClientConfig = srv.Client().Transport.(*http.Transport).TLSClientConfig.Clone() |
| + } |
| + pool := x509.NewCertPool() |
| + pool.AddCert(srv.Certificate()) |
| + wt.TLSClientConfig.RootCAs = pool |
| + |
| + var out struct { |
| + ID string `json:"id"` |
| + } |
| + if err := c.do(context.Background(), http.MethodPost, "/v1/customers", nil, "idem-1", &out); err != nil { |
| + t.Fatalf("POST through the write path: %v", err) |
| + } |
| + if out.ID != "cus_1" { |
| + t.Fatalf("decoded id = %q, want cus_1", out.ID) |
| + } |
| + if proto != "HTTP/1.1" { |
| + t.Fatalf("server saw %q, want HTTP/1.1", proto) |
| + } |
| +} |
| + |
| +func TestNewWriteTransport_OffersOnlyHTTP11(t *testing.T) { |
| + dt := http.DefaultTransport.(*http.Transport) |
| + // Ensure DefaultTransport's TLS config is populated, as it is once used. |
| + _ = dt.Clone() |
| + var before []string |
| + var hadConfig bool |
| + if dt.TLSClientConfig != nil { |
| + hadConfig = true |
| + before = append([]string(nil), dt.TLSClientConfig.NextProtos...) |
| + } |
| + cfgBefore := dt.TLSClientConfig |
| + |
| + wt := newWriteTransport() |
| + if wt.TLSClientConfig == nil { |
| + t.Fatal("write transport has no TLS config") |
| + } |
| + if got, want := wt.TLSClientConfig.NextProtos, []string{"http/1.1"}; !reflect.DeepEqual(got, want) { |
| + t.Fatalf("NextProtos = %v, want %v", got, want) |
| + } |
| + if dt.TLSClientConfig != cfgBefore { |
| + t.Fatal("DefaultTransport's TLSClientConfig pointer was replaced") |
| + } |
| + if wt.TLSClientConfig == dt.TLSClientConfig { |
| + t.Fatal("write transport shares DefaultTransport's TLSClientConfig") |
| + } |
| + if hadConfig && !reflect.DeepEqual(dt.TLSClientConfig.NextProtos, before) { |
| + t.Fatalf("DefaultTransport NextProtos mutated: %v, was %v", dt.TLSClientConfig.NextProtos, before) |
| + } |
| +} |
| + |
| +func containsProto(ps []string, p string) bool { |
| + for _, s := range ps { |
| + if s == p { |
| + return true |
| + } |
| + } |
| + return false |
| +} |