From de704f9d122073a2a17d830b790852a914aa4845 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 16 Oct 2026 20:35:43 +0200 Subject: [PATCH 1/3] =?UTF-8?q?test:=20reproduce=20#546=20=E2=80=94=20the?= =?UTF-8?q?=20gateway=20passes=20a=20worker's=20framing=20headers=20throug?= =?UTF-8?q?h=20to=20the=20caller?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gateway/relay.test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/gateway/relay.test.ts b/src/gateway/relay.test.ts index d3862b10c..88b3e0dd4 100644 --- a/src/gateway/relay.test.ts +++ b/src/gateway/relay.test.ts @@ -770,4 +770,32 @@ describe("GatewayRelay against a worker that breaks the protocol", () => { expect(await pending).toMatchObject({ code: "WORKER_UNREACHABLE", state: "rejected" }); }); + + it("drops every hop-by-hop and framing header of a worker's relay head, in any case, and keeps an ordinary header, on the response it hands the caller", async () => { + const { connection, relay } = await setup(); + const pending = relay.relay(WORKER_ID, call()); + const request = await sentFrame(connection, "relay.request"); + await openedChannel(connection); + + connection.push("relay-head", { + headers: [ + ["connection", "close"], + ["Content-Length", "5"], + ["keep-alive", "timeout=5"], + ["proxy-authenticate", "Basic realm=worker"], + ["proxy-authorization", "Basic worker-secret"], + ["te", "trailers"], + ["Te", "custom-checksum"], + ["trailer", "X-Note"], + ["TRANSFER-ENCODING", "chunked"], + ["upgrade", "h2c"], + ["x-kept", "yes"], + ], + requestId: request.id, + status: 200, + }); + const response = await pending; + + expect([...response.headers.entries()]).toEqual([["x-kept", "yes"]]); + }); }); From 7962d01523b89ef3cfb4bf95ca54c2b3eda568d5 Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 16 Oct 2026 20:44:01 +0200 Subject: [PATCH 2/3] fix(gateway): drop a worker's framing headers from the relayed response (#546) 3 failing -> 0 failing (1 failing -> 0 in relay.test.ts) --- src/gateway/relay.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/gateway/relay.ts b/src/gateway/relay.ts index 618f31b1e..918aee0cd 100644 --- a/src/gateway/relay.ts +++ b/src/gateway/relay.ts @@ -2,7 +2,12 @@ // channel wait and the wait for the head, and an idle bound covers the response body, which may be a live stream that // runs as long as someone reads it; the link bounds the channels open to a worker (ADR 0028). -import { isSimlockError, relayHeaderPairs, type AnySimlockError } from "../contract/index.js"; +import { + isRelayFramingHeader, + isSimlockError, + relayHeaderPairs, + type AnySimlockError, +} from "../contract/index.js"; import { DispatchError } from "../daemon/dispatch.js"; import { LinkChannelError, type LinkChannel } from "../link/index.js"; import { type Clock, SystemClock, type TimerHandle } from "../ports/index.js"; @@ -204,7 +209,11 @@ class Exchange { } const responseHeaders = new Headers(); try { - for (const [name, value] of headers) responseHeaders.append(name, value); + for (const [name, value] of headers) { + // why: the gateway frames its own response, so a worker'"'"'s framing headers must not reach the caller. + if (isRelayFramingHeader(name)) continue; + responseHeaders.append(name, value); + } } catch { // why: `Headers` refuses a value above U+00FF that the push schema lets through. this.#invalid(); From 5cc3e8ed949d95d572f16079030dfaaf7359798e Mon Sep 17 00:00:00 2001 From: Szymon Chmal Date: Fri, 16 Oct 2026 20:46:23 +0200 Subject: [PATCH 3/3] fix(gateway): write the framing-header comment as plain prose (#546) --- src/gateway/relay.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gateway/relay.ts b/src/gateway/relay.ts index 918aee0cd..4d0f2668f 100644 --- a/src/gateway/relay.ts +++ b/src/gateway/relay.ts @@ -210,7 +210,7 @@ class Exchange { const responseHeaders = new Headers(); try { for (const [name, value] of headers) { - // why: the gateway frames its own response, so a worker'"'"'s framing headers must not reach the caller. + // why: the gateway frames its own response, so a worker's framing headers must not reach the caller. if (isRelayFramingHeader(name)) continue; responseHeaders.append(name, value); }