Skip to content

Modern Docker Management, Designed for Everyone

fix: go1.26.6 h2c ReadHeaderTimeout regression

Kyle Mendell6d4f222389cf
diff --git a/backend/internal/bootstrap/bootstrap_test.go b/backend/internal/bootstrap/bootstrap_test.go
index 01b0814a7..154bdd445 100644
--- a/backend/internal/bootstrap/bootstrap_test.go
+++ b/backend/internal/bootstrap/bootstrap_test.go
@@ -17,6 +17,7 @@ import (
"github.com/getarcaneapp/arcane/backend/v2/internal/config"
"github.com/getarcaneapp/arcane/backend/v2/internal/database"
"github.com/getarcaneapp/arcane/backend/v2/pkg/libarcane/edge"
+ "github.com/getarcaneapp/arcane/backend/v2/pkg/utils/httpx"
tunnelpb "github.com/getarcaneapp/arcane/backend/v2/proto/tunnel/v1"
"github.com/labstack/echo/v5"
"github.com/stretchr/testify/assert"
@@ -164,7 +165,9 @@ func TestConfigureHTTPProtocolsInternal(t *testing.T) {
t.Run("plain enables http1 and unencrypted http2", func(t *testing.T) {
configuredHandler, protocols := configureHTTPProtocolsInternal(false, handler)
- assert.Same(t, handler, configuredHandler)
+ // The plain path wraps the handler to clear the stale h2c read
+ // deadline, so it is deliberately not the same handler.
+ assert.NotNil(t, configuredHandler)
require.NotNil(t, protocols)
assert.True(t, protocols.HTTP1())
assert.False(t, protocols.HTTP2())
@@ -239,6 +242,65 @@ func TestHTTP2APIResponsesDoNotUseAPIGzipInternal(t *testing.T) {
}
}
+func TestH2CStreamSurvivesPastReadHeaderTimeoutInternal(t *testing.T) {
+ // Regression guard for the go1.26.6 CVE-2026-56853 backport, which arms
+ // ReadHeaderTimeout on the raw conn before the h2c preface sniff and never
+ // clears it on the HTTP/2 handoff. Without ClearReadDeadline in the h2c
+ // handler wrapper, the connection — and every gRPC tunnel stream on it —
+ // dies with an i/o timeout exactly ReadHeaderTimeout after accept.
+ const readHeaderTimeout = 250 * time.Millisecond
+
+ release := make(chan struct{})
+ streamHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.WriteHeader(http.StatusOK)
+ w.(http.Flusher).Flush()
+ <-release
+ _, _ = w.Write([]byte("done"))
+ })
+ handler, protocols := configureHTTPProtocolsInternal(false, streamHandler)
+
+ listener, err := net.Listen("tcp", "127.0.0.1:0")
+ require.NoError(t, err)
+
+ server := &http.Server{
+ Handler: handler,
+ Protocols: protocols,
+ ReadHeaderTimeout: readHeaderTimeout,
+ ConnContext: httpx.WithConn,
+ }
+ errCh := make(chan error, 1)
+ go func() {
+ errCh <- server.Serve(listener)
+ }()
+ t.Cleanup(func() {
+ require.NoError(t, server.Shutdown(context.Background()))
+ require.ErrorIs(t, <-errCh, http.ErrServerClosed)
+ })
+
+ transport := &http2.Transport{
+ AllowHTTP: true,
+ DialTLSContext: func(ctx context.Context, network, addr string, _ *tls.Config) (net.Conn, error) {
+ return (&net.Dialer{}).DialContext(ctx, network, addr)
+ },
+ }
+ client := &http.Client{Transport: transport}
+
+ resp, err := client.Get("http://" + listener.Addr().String() + "/stream")
+ require.NoError(t, err)
+ defer func() { _ = resp.Body.Close() }()
+ require.Equal(t, "HTTP/2.0", resp.Proto)
+
+ // Keep the stream idle well past ReadHeaderTimeout before the handler
+ // writes again; on a connection with the stale deadline still armed the
+ // read below fails instead of returning the body.
+ time.Sleep(4 * readHeaderTimeout)
+ close(release)
+
+ body, err := io.ReadAll(resp.Body)
+ require.NoError(t, err)
+ require.Equal(t, "done", string(body))
+}
+
func TestHTTPServerStopCancelsStreamingRequestContextsInternal(t *testing.T) {
appCtx := t.Context()
diff --git a/backend/internal/bootstrap/server_bootstrap.go b/backend/internal/bootstrap/server_bootstrap.go
index 348294c90..9321886f1 100644
--- a/backend/internal/bootstrap/server_bootstrap.go
+++ b/backend/internal/bootstrap/server_bootstrap.go
@@ -176,6 +176,17 @@ func configureHTTPProtocolsInternal(useTLS bool, handler http.Handler) (http.Han
}
protocols.SetUnencryptedHTTP2(true)
+ inner := handler
+ handler = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ // go1.26.6 arms ReadHeaderTimeout on the raw conn before the h2c
+ // preface sniff and never clears it on the unencrypted-HTTP/2 handoff
+ // (the TLS path does), so without this every h2c connection — and the
+ // gRPC tunnel streams on it — dies ReadHeaderTimeout after accept.
+ if r.ProtoMajor == 2 && r.TLS == nil {
+ httpx.ClearReadDeadline(r.Context())
+ }
+ inner.ServeHTTP(w, r)
+ })
return handler, &protocols
}
diff --git a/backend/pkg/utils/httpx/conn_context.go b/backend/pkg/utils/httpx/conn_context.go
index da1d9ffcc..f099a7044 100644
--- a/backend/pkg/utils/httpx/conn_context.go
+++ b/backend/pkg/utils/httpx/conn_context.go
@@ -17,6 +17,8 @@ type connStateInternal struct {
mu sync.Mutex
holders int
+
+ clearReadDeadlineOnce sync.Once
}
// WithConn stores an accepted connection on its base context. Wire it up as
@@ -26,6 +28,29 @@ func WithConn(ctx context.Context, conn net.Conn) context.Context {
return context.WithValue(ctx, connContextKeyInternal{}, &connStateInternal{conn: conn})
}
+// ClearReadDeadline clears any read deadline left armed on the request's
+// underlying connection. Safe to call from any request handler, including when
+// the request never passed through WithConn; only the first call per
+// connection issues the syscall.
+//
+// It exists because go1.26.6 (the CVE-2026-56853 backport) arms
+// ReadHeaderTimeout on the raw connection before sniffing the h2c preface and
+// hands the connection to the HTTP/2 server without clearing it. The HTTP/2
+// server tracks liveness with timers, never read deadlines, so the stale
+// absolute deadline survives and tears the connection down — with every stream
+// on it — exactly ReadHeaderTimeout after accept. By the time a handler runs
+// the headers are already parsed, so clearing the deadline does not weaken the
+// slowloris protection the timeout is for.
+func ClearReadDeadline(ctx context.Context) {
+ state, _ := ctx.Value(connContextKeyInternal{}).(*connStateInternal)
+ if state == nil {
+ return
+ }
+ state.clearReadDeadlineOnce.Do(func() {
+ _ = state.conn.SetReadDeadline(time.Time{})
+ })
+}
+
// AcquireDeadPeerTimeout bounds how long data written to the request's
// connection may stay unacknowledged before the kernel tears it down, and
// returns a release function restoring the system default once every caller