From 6d3b086e8cd52f4205d3873d93d2405cb373b41b Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 9 Nov 2026 04:48:21 -0800 Subject: [PATCH 1/2] chore(quest): claim quest/m2/api-shape/auth-sign.md Quest-Claim: 9011539c76d261b6 From d4e9ca1c12d06ac4fdb1edc420473c9604ed80e1 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 9 Nov 2026 04:54:15 -0800 Subject: [PATCH 2/2] refactor(js)!: Key.sign takes exactly Claims `@moq/auth`'s Key.sign and KeySet.sign take Claims, as Rust's sign(&Claims) does, so each role has one spelling. The legacy put/get input is refused rather than accepted. Tokens written are unchanged: subtree grants are still written as put/get so older verifiers accept them, and verify still reads legacy tokens. Co-Authored-By: Claude Haiku 5.5 --- js/auth/api/index.api.md | 50 ++------------------------------- js/auth/src/key.test.ts | 8 ++++-- js/auth/src/key.ts | 18 ++++-------- js/auth/src/set.ts | 2 +- js/auth/src/wire.ts | 6 +++- quest/m2/api-shape/README.md | 1 - quest/m2/api-shape/auth-sign.md | 25 ----------------- 7 files changed, 18 insertions(+), 92 deletions(-) delete mode 100644 quest/m2/api-shape/auth-sign.md diff --git a/js/auth/api/index.api.md b/js/auth/api/index.api.md index 31ba791c200..b59c4964e38 100644 --- a/js/auth/api/index.api.md +++ b/js/auth/api/index.api.md @@ -178,30 +178,7 @@ export const Key: { generate: (algorithm: Algorithm, kid?: string) => Promise; parse: (jwk: string) => Key; public: (key: Key) => PublicKey; - sign: (key: Key, claims: Omit<{ - exp?: number; - get?: string | string[]; - iat?: number; - iss?: unknown; - jti?: unknown; - nbf?: number; - publish?: string[] | { - path: string[]; - rate: number; - }; - put?: string | string[]; - root?: string; - sub?: unknown; - subscribe?: string[] | { - path: string[]; - rate: number; - }; - }, "publish" | "subscribe"> & { - publish?: string[]; - publish_rate?: number; - subscribe?: string[]; - subscribe_rate?: number; - }) => Promise; + sign: (key: Key, claims: Claims) => Promise; verify: (key: PublicKey | SymmetricKey, token: string) => Promise; }; @@ -405,30 +382,7 @@ export const KeySet: { find: (set: KeySet, kid: string) => Key | undefined; parse: (jwks: string) => KeySet; public: (set: KeySet) => PublicKeySet; - sign: (set: KeySet, claims: Omit<{ - exp?: number; - get?: string | string[]; - iat?: number; - iss?: unknown; - jti?: unknown; - nbf?: number; - publish?: string[] | { - path: string[]; - rate: number; - }; - put?: string | string[]; - root?: string; - sub?: unknown; - subscribe?: string[] | { - path: string[]; - rate: number; - }; - }, "publish" | "subscribe"> & { - publish?: string[]; - publish_rate?: number; - subscribe?: string[]; - subscribe_rate?: number; - }) => Promise; + sign: (set: KeySet, claims: Claims) => Promise; verify: (set: KeySet, token: string) => Promise; }; diff --git a/js/auth/src/key.test.ts b/js/auth/src/key.test.ts index 788a2ece0b6..0ef5749f111 100644 --- a/js/auth/src/key.test.ts +++ b/js/auth/src/key.test.ts @@ -805,13 +805,15 @@ test("sign - subtree grants are written as legacy put/get", async () => { expect(payload).toEqual({ root: "test-path", put: ["alice"], get: [""] }); }); -test("sign - legacy-shaped input cannot slip past a key scope", async () => { +test("sign - refuses the legacy put/get spelling, even within scope", async () => { const scoped: Key = { ...Key.parse(encodeJwk(testKey)), scope: { root: "demo", publish: ["inside/**"] }, }; - const legacy = { root: "demo", put: ["outside"] } as unknown as Parameters[1]; - await expect(Key.sign(scoped, legacy)).rejects.toThrow(/scope/); + const inside = { root: "demo", put: ["inside"] } as unknown as Claims; + await expect(Key.sign(scoped, inside)).rejects.toThrow("legacy put/get"); + const outside = { root: "demo", put: ["outside"] } as unknown as Claims; + await expect(Key.sign(scoped, outside)).rejects.toThrow("legacy put/get"); }); test("key scope is enforced when signing and verifying", async () => { diff --git a/js/auth/src/key.ts b/js/auth/src/key.ts index 22a1971db81..4a7b2b00bca 100644 --- a/js/auth/src/key.ts +++ b/js/auth/src/key.ts @@ -195,26 +195,18 @@ function parse(jwk: string): Key { * wire rather than being stamped with the current time. * * Takes each role as its patterns, capped by `publish_rate` or `subscribe_rate` beside - * it, as the decoded {@link Claims} spell them; the `{path, rate}` wire form is refused. + * it, as the decoded {@link Claims} spell them; the `{path, rate}` wire form and the + * legacy `put`/`get` spelling are refused. * * Throws on a root spelled with an empty segment, a `\` escaping anything but `\` or * `/`, or more than 4096 bytes. Verifying stays lenient on the empty segments, so tokens * minted before stay valid. */ -async function sign( - key: Key, - claims: Omit, "publish" | "subscribe"> & { - publish?: string[]; - publish_rate?: number; - subscribe?: string[]; - subscribe_rate?: number; - }, -): Promise { +async function sign(key: Key, claims: Claims): Promise { ensureOperationSupported(key, "sign"); - // Scope-check and sign what the schema parsed, never the raw input: an untyped - // caller could pass legacy `put`/`get` fields the scope check would not see. The - // caps nest back into their roles first, which the schema refuses a role already in. + // Scope-check and sign what the schema parsed, never the raw input. The caps nest + // back into their roles first, which the schema refuses a role already in. let parsed: Claims; try { parsed = ClaimsSchema.parse(nestRates(claims)); diff --git a/js/auth/src/set.ts b/js/auth/src/set.ts index c3502fc37ca..110114b4fb6 100644 --- a/js/auth/src/set.ts +++ b/js/auth/src/set.ts @@ -70,7 +70,7 @@ function find(set: KeySet, kid: string): Key | undefined { } /** Sign the claims with the first key that permits signing and contains signing material. */ -async function sign(set: KeySet, claims: Parameters[1]): Promise { +async function sign(set: KeySet, claims: Claims): Promise { const key = set.keys.find((key) => key.key_ops.includes("sign") && (key.kty === "oct" || key.d !== undefined)); if (!key) throw new Error("Cannot find signing key"); return await Key.sign(key, claims); diff --git a/js/auth/src/wire.ts b/js/auth/src/wire.ts index f59acbeea1e..f9e9a8e3c64 100644 --- a/js/auth/src/wire.ts +++ b/js/auth/src/wire.ts @@ -127,12 +127,16 @@ export function decodeRoles(claims: T) { const { publish_rate, subscribe_rate, ...rest } = claims; + if ("put" in rest || "get" in rest) { + throw new Error("legacy put/get grants are refused; sign publish and subscribe instead"); + } for (const role of [rest.publish, rest.subscribe]) { if (role !== undefined && !Array.isArray(role)) { throw new Error("a role is a pattern list, capped by publish_rate or subscribe_rate"); diff --git a/quest/m2/api-shape/README.md b/quest/m2/api-shape/README.md index c32ca6acaf8..1c4186c1daf 100644 --- a/quest/m2/api-shape/README.md +++ b/quest/m2/api-shape/README.md @@ -60,4 +60,3 @@ Rejected in planning: ## Required - [moq-net's route stream goes public](/quest/m2/api-shape/net.md) - un-hide `origin::Consumer::routes` and reshape `RouteEvent`, now that #8063 merged -- [JS Key.sign takes exactly Claims](/quest/m2/api-shape/auth-sign.md) - `@moq/auth` signs only `Claims`, with no legacy `put`/`get` input, like Rust diff --git a/quest/m2/api-shape/auth-sign.md b/quest/m2/api-shape/auth-sign.md deleted file mode 100644 index feb70a43a76..00000000000 --- a/quest/m2/api-shape/auth-sign.md +++ /dev/null @@ -1,25 +0,0 @@ -# [XS] JS Key.sign takes exactly Claims - -## Goal - -`@moq/auth`'s `Key.sign` takes exactly `Claims`, as Rust's -`moq_auth::Key::sign(&Claims)` does: its input no longer accepts the legacy -`put`/`get` role spelling, so each role has one spelling. Tokens it writes -are unchanged: when the legacy form says the same thing, it is still written -that way so older verifiers accept it, and `verify` still reads legacy -tokens. - -## Plan - -Planned 2026-11-09 (maintainer, /quest-complete follow-up of -[moq-dev/moq#8296](https://github.com/moq-dev/moq/pull/8296), which settles -`Key.sign`'s caps spelling). ✅ Its own small breaking PR in this epic -(rejected: folding it into #8296 mid-iterate; dropping it). - -`sign` in `js/auth/src/key.ts` takes `z.input` plus -the rate fields, so its type still admits whatever the schema parses. Narrow -the parameter to `Claims` (as `verify` returns it), keep the scope check on -the parsed value, and update `js/auth/api/*.api.md`. - -Public API: `@moq/auth` `Key.sign` no longer accepts `put`/`get` input. -Migrate: pass `publish`/`subscribe` roles. Wire: none.