feat(gateway): forward application identity on WebSocket upgrades
Adds gatewayWebSocketBackendHeaders so proxied upgrades carry application identity while Bun keeps ownership of WebSocket framing. Pre-existing working-tree change, committed as-is rather than authored here. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import {
|
||||
forwardAuthFailure,
|
||||
forwardAuthHeaders,
|
||||
gatewayProxyHeaders,
|
||||
gatewayWebSocketBackendHeaders,
|
||||
stripUntrustedInternalHeaders,
|
||||
gatewayRestartDelay,
|
||||
internalError,
|
||||
@@ -37,6 +38,35 @@ test("gateway disables compression for its internal proxy hop", () => {
|
||||
expect(headers.get("x-forwarded-for")).toBe("127.0.0.1");
|
||||
});
|
||||
|
||||
test("gateway WebSocket bridge forwards validated application identity", () => {
|
||||
const request = new Request("http://web.localhost:3000/__wrnexus/hmr", {
|
||||
headers: {
|
||||
host: "web.localhost:3000",
|
||||
origin: "http://web.localhost:3000",
|
||||
cookie: "session=abc",
|
||||
connection: "Upgrade",
|
||||
upgrade: "websocket",
|
||||
"sec-websocket-key": "test-key",
|
||||
},
|
||||
});
|
||||
const headers = gatewayWebSocketBackendHeaders(
|
||||
request,
|
||||
new URL(request.url),
|
||||
"127.0.0.1",
|
||||
true,
|
||||
"http://127.0.0.1:3001",
|
||||
);
|
||||
|
||||
expect(headers.origin).toBe("http://127.0.0.1:3001");
|
||||
expect(headers.cookie).toBe("session=abc");
|
||||
expect(headers["x-forwarded-host"]).toBe("web.localhost:3000");
|
||||
expect(headers["x-forwarded-proto"]).toBe("http");
|
||||
expect(headers.host).toBeUndefined();
|
||||
expect(headers.connection).toBeUndefined();
|
||||
expect(headers.upgrade).toBeUndefined();
|
||||
expect(headers["sec-websocket-key"]).toBeUndefined();
|
||||
});
|
||||
|
||||
test("gateway proxy headers do not preserve the RPC internal marker", () => {
|
||||
const request = new Request("http://localhost:3000/path", {
|
||||
headers: { "x-wrnexus-internal": "1" },
|
||||
|
||||
Reference in New Issue
Block a user