Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
f5a5968
chore: claim request ID order quest
kixelated Oct 10, 2026
88a1503
fix(moq-net): permanently spend incoming IETF request IDs
kixelated Oct 10, 2026
f1ab951
chore(quest): claim AUTH protocol violations
kixelated Oct 10, 2026
ec90c55
fix(net): close sessions on malformed AUTH messages
kixelated Oct 10, 2026
def0726
quest: retain AUTH request-ID validation dependency
kixelated Oct 10, 2026
7aa4289
Merge remote-tracking branch 'origin/main' into astra/iterate-5235
kixelated Oct 11, 2026
97776e4
fix(net): require the next incoming IETF request ID
kixelated Oct 11, 2026
90b8490
quest: retain draft-16 request ordering decision
kixelated Oct 11, 2026
0afe789
fix(net): allow bounded draft-16 request ID reordering
kixelated Oct 11, 2026
f0b6173
Merge remote-tracking branch 'origin/main' into astra/iterate-5279
kixelated Oct 11, 2026
f558dac
Merge request-ID admission dependency into AUTH validation
kixelated Oct 11, 2026
eee8e9e
fix(net): share modern request ID history across AUTH and requests
kixelated Oct 11, 2026
be648e5
Merge origin/main into quest/m1/auth/violations
kixelated Oct 12, 2026
c30f2f7
fix(net): share the draft-16 skipped-run tracker with draft-17+ reque…
kixelated Oct 12, 2026
73ee708
fix(net): refuse request IDs past 2^62 and close on truncated Lite AU…
kixelated Oct 12, 2026
7d5db62
Merge remote-tracking branch 'origin/main' into worktree-agent-ac22d5…
kixelated Oct 12, 2026
c64db18
quest: complete AUTH protocol violations
kixelated Oct 12, 2026
146fdf8
drafts(lite): record the session-fatal AUTH stream rules in the chang…
kixelated Oct 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion drafts/draft-lcurley-moq-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ After an AUTH_ERROR the acceptor closes its side of the stream.
The presenter withdraws a token by closing or resetting its side of the stream, and the acceptor then closes its own.
An acceptor that closes its side without an AUTH_ERROR ends the grant without a reason.

A receiver MUST close the session with PROTOCOL_VIOLATION if an AUTH message fails to decode, has trailing body bytes, or has an unexpected type for its direction.
A presenter sends exactly one AUTH on its request stream; any additional message is a PROTOCOL_VIOLATION.
Comment on lines +92 to +93

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Record the new AUTH semantics in both changelogs

These additions change wire semantics for malformed AUTH messages and request-ID reuse, but neither modified draft records the changes in its in-progress changelog, and the AUTH draft has no changelog appendix at all. Add concise changelog entries so this protocol revision follows the draft maintenance requirement.

AGENTS.md reference: drafts/AGENTS.md:L18-L18

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 146fdf8: the lite draft's moq-lite-07 changelog now has a bullet for the session-fatal Auth Stream rules. The AUTH draft has no published revision yet, so it has no changelog appendix to update. drafts/AGENTS.md says not to add a section for an unpublished version.

(Written by Claude Opus 5.5)


## Scope {#scope}

An endpoint's scope is the union of the grants of its open Auth requests.
Expand Down Expand Up @@ -132,7 +135,8 @@ AUTH Message {
~~~

**Request ID**:
The request's identifier, allocated like that of any other request ({{moqt}}).
The request's identifier, allocated from the same space as every other request ({{moqt}}).
A duplicate or wrong-parity Request ID closes the session with INVALID_REQUEST_ID, including an ID from an AUTH that has ended.

**Token**:
The credential to verify, opaque to this extension.
Expand Down Expand Up @@ -162,6 +166,7 @@ A namespace prefix the presenter may subscribe to and discover.

**Expires**:
The number of milliseconds until the grant lapses, or 0 for never.
Expires MUST NOT exceed 2^53 - 1 milliseconds; a larger value is a PROTOCOL_VIOLATION.
The acceptor revokes a lapsed grant with AUTH_ERROR, and the presenter uses Expires to present a replacement token in time.

## AUTH_ERROR {#auth-error}
Expand All @@ -179,6 +184,7 @@ AUTH_ERROR Message {
~~~

**Error Code**:
A code MUST fit in 32 bits; a larger value is a PROTOCOL_VIOLATION.
A code from the REQUEST_ERROR registry ({{moqt}}): UNAUTHORIZED, MALFORMED_AUTH_TOKEN, EXPIRED_AUTH_TOKEN, or NOT_SUPPORTED ({{prefixes}}).

**Reason Phrase**:
Expand Down
4 changes: 4 additions & 0 deletions drafts/draft-lcurley-moq-lite.md
Original file line number Diff line number Diff line change
Expand Up @@ -1457,6 +1457,9 @@ A pattern that breaks any of these rules is a PROTOCOL_VIOLATION.

A grant covers a request when one of its patterns matches the path.

An endpoint MUST close the session with PROTOCOL_VIOLATION when an AUTH stream message fails to decode, has trailing body bytes, or has an unexpected type for its direction.
The opener sends exactly one AUTH; any additional message on its side is a PROTOCOL_VIOLATION.

## AUTH_ERROR {#auth-error}
AUTH_ERROR refuses a token, or revokes it after an AUTH_OK.

Expand Down Expand Up @@ -1566,6 +1569,7 @@ The `Message Length` describes the payload size on the wire.
- Added the AUTH_TOKEN_CACHE_OVERFLOW (0x13) and UNKNOWN_AUTH_TOKEN_ALIAS (0x17) session codes, with moq-transport's meaning.
- Limited AUTH_OK Expires to 2^53 - 1 milliseconds, with an out-of-range value closing the session with PROTOCOL_VIOLATION.
- Invalid UTF-8 or an oversized AUTH_ERROR reason closes the session with PROTOCOL_VIOLATION.
- An Auth Stream message that fails to decode, has trailing body bytes, or has an unexpected type, or a second AUTH from the opener, closes the session with PROTOCOL_VIOLATION.
- Added NOT_SUPPORTED (0x30) to session errors; unsupported Auth Stream tokens and grants use AUTH_ERROR before or after a grant.
- Added the Auth Stream (0x7) with AUTH, AUTH_OK, and AUTH_ERROR: either endpoint presents a token on its own stream and learns the [path patterns](#path-pattern) it may publish and subscribe to. The union of a session's open grants is its scope. A shrink withdraws what it no longer covers, and an announcement outside the scope closes the session with UNAUTHORIZED. A peer without the stream resets it.

Expand Down
29 changes: 28 additions & 1 deletion js/net/bench/request-ids.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Request-ID admission cost across independent sessions and reordered windows.
import { ControlStreamAdapter } from "../src/ietf/adapter.ts";
import { ControlStreamAdapter, SpentIds } from "../src/ietf/adapter.ts";
import { Version } from "../src/ietf/version.ts";
import { Stream } from "../src/stream.ts";

Expand Down Expand Up @@ -78,3 +78,30 @@ try {
} finally {
console.debug = debug;
}

// Draft 17+ has no MAX_REQUEST_ID window, yet still remembers skipped runs to refuse reuse.
console.log("modern_mode,sessions,requests,admit_us,accepted");
for (const mode of ["ordered", "reordered", "scattered"]) {
for (const sessions of [1, 8, 32]) {
for (const requests of [8, 128, 220_000]) {
const ids = order(mode, requests);
const rounds = Math.max(1, Math.floor(8192 / requests));
let elapsed = 0;
let accepted = 0;
for (let round = 0; round < rounds; round++) {
const receivers = Array.from({ length: sessions }, () => new SpentIds(0n));
const start = performance.now();
for (const receiver of receivers) {
for (const id of ids) {
receiver.spend(id);
accepted++;
}
}
elapsed += performance.now() - start;
}
console.log(
`modern-${mode},${sessions},${requests},${((elapsed * 1000) / rounds).toFixed(2)},${accepted / rounds}`,
);
}
}
}
211 changes: 209 additions & 2 deletions js/net/src/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import type { Getter } from "@moq/signals";
import { type Grant, type Issued, Unsupported } from "./auth.ts";
import { accept as acceptSession, connect as connectSession, type Established } from "./connection/index.ts";
import { SessionCode, SessionError, StreamCode, toStreamCode } from "./error.ts";
import { AuthMessage as IetfAuthMessage, IetfAuthWire } from "./ietf/auth.ts";
import * as Ietf from "./ietf/index.ts";
import { LiteAuthWire } from "./lite/auth.ts";
import * as IetfMessage from "./ietf/message.ts";
import { TrackStatusRequest } from "./ietf/track.ts";
import { Version as IetfVersion } from "./ietf/version.ts";
import { AuthMessage as LiteAuthMessage, LiteAuthWire } from "./lite/auth.ts";
import * as Lite from "./lite/index.ts";
import * as LiteMessage from "./lite/message.ts";
import { createMockTransportPair, type MockTransport } from "./mock.ts";
import { Producer as OriginProducer } from "./origin.ts";
import * as Path from "./path.ts";
import { Writer } from "./stream.ts";
import { type Stream, Writer } from "./stream.ts";
import { withTimeout } from "./util/timeout.ts";
import { wireOf } from "./wire.ts";

Expand Down Expand Up @@ -443,3 +448,205 @@ test("a revoked grant resets its subscriptions with UNAUTHORIZED", async () => {
server.abort();
}
});

// Capture the acceptor's actual AUTH writer after a valid setup grant. The following
// bytes travel through the same connection dispatcher and presenter as a real peer.
describe.each([Lite.ALPN_07_WIP, Ietf.ALPN.DRAFT_17, Ietf.ALPN.DRAFT_22])("AUTH violations %s", (protocol) => {
test("a second presenter message closes the session", async () => {
const streams: Stream[] = [];
const prototype = protocol === Lite.ALPN_07_WIP ? LiteAuthWire.prototype : IetfAuthWire.prototype;
const original = prototype.present;
const spy = spyOn(prototype, "present").mockImplementation(async function (
this: LiteAuthWire & IetfAuthWire,
token,
) {
const stream = await original.call(this, token);
streams.push(stream);
return stream;
});
let pair: Pair | undefined;
try {
pair = await connect({ protocol });
await waitFor(pair.client.auth.grant, (g) => g !== undefined);
await waitFor(pair.server.auth.grant, (g) => g !== undefined);
await streams[0]?.writer.u53(0);
expect((await withTimeout(pair.transport.closed, 100, "second AUTH did not close")).closeCode).toBe(
SessionCode.ProtocolViolation,
);
} finally {
spy.mockRestore();
pair?.client.abort();
pair?.server.abort();
}
});

test("a malformed presenter AUTH closes the session", async () => {
const pair = await connect({ protocol });
await waitFor(pair.client.auth.grant, (g) => g !== undefined);
await waitFor(pair.server.auth.grant, (g) => g !== undefined);
const lite = protocol === Lite.ALPN_07_WIP;
const prototype = lite ? LiteAuthMessage.prototype : IetfAuthMessage.prototype;
const spy = spyOn(prototype, "encode").mockImplementation(async (writer: Writer) => {
const body = async (w: Writer) => {
if (!lite) await w.u62(2n);
await w.u53(2);
};
if (lite) await LiteMessage.encode(writer, body);
else await IetfMessage.encode(writer, body, IetfAuthMessage.id);
});
const added = pair.client.auth.add("bad").catch(() => undefined);
try {
expect((await withTimeout(pair.transport.closed, 100, "malformed AUTH did not close")).closeCode).toBe(
SessionCode.ProtocolViolation,
);
} finally {
spy.mockRestore();
pair.client.abort();
pair.server.abort();
await added;
}
});

for (const fault of [
"unknown reply",
"oversized code",
"truncated error",
"extra body",
"oversized expiry",
] as const) {
test(`${fault} closes the session`, async () => {
const streams: Stream[] = [];
const lite = protocol === Lite.ALPN_07_WIP;
const prototype = lite ? LiteAuthWire.prototype : IetfAuthWire.prototype;
const original = prototype.grant;
const spy = spyOn(prototype, "grant").mockImplementation(async function (
this: LiteAuthWire & IetfAuthWire,
stream,
value,
) {
streams.push(stream);
await original.call(this, stream, value);
});
let pair: Pair | undefined;
try {
pair = await connect({ protocol });
await waitFor(pair.client.auth.grant, (g) => g !== undefined);
await waitFor(pair.server.auth.grant, (g) => g !== undefined);
const stream = streams[0];
if (!stream) throw new Error("setup AUTH writer missing");
if (fault === "unknown reply") {
await stream.writer.u53(99);
} else {
const body = async (writer: Writer) => {
if (fault === "oversized expiry") {
await writer.u53(0);
await writer.u53(0);
await writer.u62(1n << 53n);
} else {
await writer.u62(fault === "oversized code" ? 1n << 32n : 1n);
if (fault !== "truncated error") await writer.string("");
if (fault === "extra body") await writer.u53(0);
}
};
const id = fault === "oversized expiry" ? (lite ? 0 : 0x40b62) : lite ? 1 : 0x40b63;
if (lite) await LiteMessage.encode(stream.writer, body, { id });
else await IetfMessage.encode(stream.writer, body, id);
}
expect((await withTimeout(pair.transport.closed, 100, "malformed AUTH did not close")).closeCode).toBe(
SessionCode.ProtocolViolation,
);
} finally {
spy.mockRestore();
pair?.client.abort();
pair?.server.abort();
}
});
}
});

// AUTH shares its ID space with every other request from the same peer.
describe.each([Ietf.ALPN.DRAFT_17, Ietf.ALPN.DRAFT_22])("AUTH request IDs %s", (protocol) => {
for (const client of [true, false]) {
for (const fault of ["reused", "wrong parity"] as const) {
test(`${client ? "client" : "server"} ${fault} closes the session`, async () => {
const pair = await connect({ protocol });
await waitFor(pair.client.auth.grant, (g) => g !== undefined);
await waitFor(pair.server.auth.grant, (g) => g !== undefined);
const original = IetfAuthMessage.prototype.encode;
const spy = spyOn(IetfAuthMessage.prototype, "encode").mockImplementation(async function (
this: IetfAuthMessage,
writer,
version,
) {
this.requestId = fault === "reused" ? (client ? 0n : 1n) : client ? 1n : 0n;
await original.call(this, writer, version);
});
const added = (client ? pair.client : pair.server).auth.add("bad ID").catch(() => undefined);
try {
expect(
(await withTimeout(pair.transport.closed, 100, "invalid AUTH ID left session open")).closeCode,
).toBe(SessionCode.InvalidRequestId);
} finally {
spy.mockRestore();
pair.client.abort();
pair.server.abort();
await added;
}
});
}
}
});

for (const [protocol, version] of [
[Ietf.ALPN.DRAFT_17, IetfVersion.DRAFT_17],
[Ietf.ALPN.DRAFT_22, IetfVersion.DRAFT_22],
] as const) {
test(`TRACK_STATUS cannot reuse setup AUTH ID on ${protocol}`, async () => {
const pair = await connect({ protocol });
await waitFor(pair.client.auth.grant, (g) => g !== undefined);
try {
const raw = await pair.transport.createBidirectionalStream();
const writer = new Writer(raw.writable, version);
await writer.u53(TrackStatusRequest.id);
await new TrackStatusRequest({
requestId: 0n,
trackNamespace: Path.from("test"),
trackName: "video",
}).encode(writer, version);
expect(
(await withTimeout(pair.transport.closed, 100, "cross-request reuse left session open")).closeCode,
).toBe(SessionCode.InvalidRequestId);
} finally {
pair.client.abort();
pair.server.abort();
}
});
}

for (const protocol of [Ietf.ALPN.DRAFT_17, Ietf.ALPN.DRAFT_22]) {
test(`AUTH accepts reordered IDs on ${protocol}`, async () => {
const pair = await connect({ protocol });
await waitFor(pair.client.auth.grant, (g) => g !== undefined);
await waitFor(pair.server.auth.grant, (g) => g !== undefined);
const original = IetfAuthMessage.prototype.encode;
const spy = spyOn(IetfAuthMessage.prototype, "encode").mockImplementation(async function (
this: IetfAuthMessage,
writer,
version,
) {
// Swap the next two independently opened request IDs, preserving endpoint parity.
this.requestId = this.requestId < 4n ? this.requestId + 2n : this.requestId - 2n;
await original.call(this, writer, version);
});
try {
for (const endpoint of [pair.client, pair.server]) {
await expect(endpoint.auth.add("first")).rejects.toBeInstanceOf(Unsupported);
await expect(endpoint.auth.add("second")).rejects.toBeInstanceOf(Unsupported);
}
} finally {
spy.mockRestore();
pair.client.abort();
pair.server.abort();
}
});
}
Loading
Loading