fix: harden application trust boundaries (#1317)

This commit is contained in:
ZacharyZcR
2026-08-24 07:55:17 +08:00
committed by GitHub
parent 30d72554fc
commit 2de9bb236b
31 changed files with 287 additions and 132 deletions
+28
View File
@@ -0,0 +1,28 @@
import { describe, expect, it } from "vitest";
import type { IncomingMessage } from "http";
import { extractWebSocketToken } from "../../utils/ws-auth.js";
function request(headers: Record<string, string>): IncomingMessage {
return { headers } as IncomingMessage;
}
describe("extractWebSocketToken", () => {
it("reads JWTs from the WebSocket subprotocol without using the URL", () => {
expect(
extractWebSocketToken(
request({ "sec-websocket-protocol": "termix.jwt.header.payload.sig" }),
),
).toBe("header.payload.sig");
});
it("prefers the HttpOnly cookie over renderer-provided protocols", () => {
expect(
extractWebSocketToken(
request({
cookie: "jwt=cookie-token",
"sec-websocket-protocol": "termix.jwt.protocol-token",
}),
),
).toBe("cookie-token");
});
});