From 2cb981d3fee48db8012a1902636f1192f441417b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 28 Oct 2026 00:31:12 -0700 Subject: [PATCH] fix(auth): accept WebTransport and future transport names on release Backport the transport schema from #5293 so a published @moq/auth parses the `webtransport` value relays on main report, and reads any future name as `unknown` instead of refusing the request. Bump @moq/auth to 0.2.3 so Release JS publishes it. Co-Authored-By: Claude Opus 5.5 --- bun.lock | 2 +- js/auth/api/index.api.md | 36 ++++++++++++++++++++++++++++-------- js/auth/package.json | 2 +- js/auth/src/contract.test.ts | 21 +++++++++++++++++---- js/auth/src/contract.ts | 20 +++++++++++++++++++- 5 files changed, 66 insertions(+), 15 deletions(-) diff --git a/bun.lock b/bun.lock index 4a30839d86c..e3ab842bea4 100644 --- a/bun.lock +++ b/bun.lock @@ -75,7 +75,7 @@ }, "js/auth": { "name": "@moq/auth", - "version": "0.2.2", + "version": "0.2.3", "bin": { "moq-auth": "./src/cli.ts", }, diff --git a/js/auth/api/index.api.md b/js/auth/api/index.api.md index 4bdcc61f398..d0963684d68 100644 --- a/js/auth/api/index.api.md +++ b/js/auth/api/index.api.md @@ -580,14 +580,19 @@ export { Request_2 as Request } export const RequestSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{ id: z.ZodMiniString; node: z.ZodMiniString; - transport: z.ZodMiniEnum<{ + transport: z.ZodMiniPipe, z.ZodMiniCatch; + webtransport: "webtransport"; + }>>>; remote: z.ZodMiniOptional>; local: z.ZodMiniOptional>; server_name: z.ZodMiniOptional>; @@ -612,14 +617,19 @@ export const RequestSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{ }, z.core.$strip>, z.ZodMiniObject<{ id: z.ZodMiniString; node: z.ZodMiniString; - transport: z.ZodMiniEnum<{ + transport: z.ZodMiniPipe, z.ZodMiniCatch; + webtransport: "webtransport"; + }>>>; remote: z.ZodMiniOptional>; local: z.ZodMiniOptional>; server_name: z.ZodMiniOptional>; @@ -644,14 +654,19 @@ export const RequestSchema: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{ }, z.core.$strip>, z.ZodMiniObject<{ id: z.ZodMiniString; node: z.ZodMiniString; - transport: z.ZodMiniEnum<{ + transport: z.ZodMiniPipe, z.ZodMiniCatch; + webtransport: "webtransport"; + }>>>; remote: z.ZodMiniOptional>; local: z.ZodMiniOptional>; server_name: z.ZodMiniOptional>; @@ -740,14 +755,19 @@ function toPublic_2(set: KeySet): PublicKeySet; export type Transport = z.infer; -export const TransportSchema: z.ZodMiniEnum<{ +export const TransportSchema: z.ZodMiniPipe, z.ZodMiniCatch; + webtransport: "webtransport"; +}>>>; function verify(key: PublicKey | SymmetricKey, token: string): Promise; diff --git a/js/auth/package.json b/js/auth/package.json index 58481002221..dd2aeff6b76 100644 --- a/js/auth/package.json +++ b/js/auth/package.json @@ -1,7 +1,7 @@ { "name": "@moq/auth", "type": "module", - "version": "0.2.2", + "version": "0.2.3", "description": "Media over QUIC - the authorization contract: requests, grants, and the JWT that rides them", "license": "(MIT OR Apache-2.0)", "repository": { diff --git a/js/auth/src/contract.test.ts b/js/auth/src/contract.test.ts index aad28a21157..0f1057b4274 100644 --- a/js/auth/src/contract.test.ts +++ b/js/auth/src/contract.test.ts @@ -81,11 +81,24 @@ test("a SETUP token parses as the Rust vector", () => { } }); -test("a connect must not carry end facts, and an unknown transport is refused", () => { +test("a connect must not carry end facts", () => { expect(() => RequestSchema.parse({ id: "1", event: "end", node: "n", transport: "quic", path: "/" })).toThrow(); - expect(() => - RequestSchema.parse({ id: "1", event: "connect", node: "n", transport: "carrier-pigeon", path: "/" }), - ).toThrow(); +}); + +test("WebTransport and future transport names follow the Rust contract", () => { + for (const [incoming, expected] of [ + ["webtransport", "webtransport"], + ["carrier-pigeon", "unknown"], + ] as const) { + const request = RequestSchema.parse({ id: "1", event: "connect", node: "n", transport: incoming, path: "/" }); + expect(request.transport).toBe(expected); + } +}); + +test("malformed transport values are refused", () => { + for (const transport of [undefined, null, 1, {}, []]) { + expect(() => RequestSchema.parse({ id: "1", event: "connect", node: "n", transport, path: "/" })).toThrow(); + } }); test("a grant round trips and is validated", () => { diff --git a/js/auth/src/contract.ts b/js/auth/src/contract.ts index 4768f9776c0..c783b677cae 100644 --- a/js/auth/src/contract.ts +++ b/js/auth/src/contract.ts @@ -11,7 +11,25 @@ import * as z from "@zod/mini"; import { PatternListSchema } from "./claims.ts"; /** How a session reached the relay; `http` is a one-shot request on the relay's web listener. */ -export const TransportSchema = z.enum(["quic", "iroh", "websocket", "tcp", "unix", "http"]); +export const TransportSchema = z.pipe( + z.string(), + z.catch( + z.enum([ + "quic", + "iroh", + "websocket", + "tcp", + "unix", + "http", + "rtmp", + "srt", + "webrtc", + "webtransport", + "unknown", + ]), + "unknown", + ), +); export type Transport = z.infer; /** The single direction a client declared at SETUP. */