From c26b8db2e8a424011b9c9df3f0761612255ef589 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:27:43 -0700 Subject: [PATCH 1/2] chore(quest): claim quest/m1/release-audit/js-partial-group.md Quest-Claim: 9387dc9fbd09ec8f From 402c258050ff69ad6fb3144e3efc603923bb7300 Mon Sep 17 00:00:00 2001 From: Luke Curley <432854+kixelated@users.noreply.github.com> Date: Thu, 22 Oct 2026 14:30:50 -0700 Subject: [PATCH 2/2] fix(net): refuse partial lite groups and close the session on group violations The JS lite subscriber read a group stream declaring `frameStart` above 0 as if it started at frame 0, misnumbering every frame resumption and deduplication rely on. It never asks for a mid-group start, so such a group is a peer bug: refuse it as a ProtocolViolation, folding in the compressed-group check. `runGroup` caught every error and reset only that stream, so this violation, and the existing one for a group past the declared end, never reached the connection. A violation now escapes `runGroup` and the connection closes the session on it; ordinary group errors stay stream-scoped. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EeyiEy5FWz3z44DYZVo7vU --- js/net/src/lite/connection.test.ts | 58 +++++++++++++++++++++- js/net/src/lite/subscriber.ts | 17 +++++-- js/net/src/lite/tail.test.ts | 10 +++- quest/m1/release-audit/README.md | 3 +- quest/m1/release-audit/js-partial-group.md | 35 ------------- quest/m1/subscribe-ranges/js.md | 6 +-- 6 files changed, 82 insertions(+), 47 deletions(-) delete mode 100644 quest/m1/release-audit/js-partial-group.md diff --git a/js/net/src/lite/connection.test.ts b/js/net/src/lite/connection.test.ts index 45c2526f73b..2c70ac2ec34 100644 --- a/js/net/src/lite/connection.test.ts +++ b/js/net/src/lite/connection.test.ts @@ -12,9 +12,17 @@ import { wireOf } from "../wire.ts"; import { Connection, probeLevel } from "./connection.ts"; import { Fetch } from "./fetch.ts"; import { Goaway } from "./goaway.ts"; +import { Group as GroupMessage } from "./group.ts"; import { ProbeLevel, Setup } from "./setup.ts"; import { DataType, StreamId } from "./stream.ts"; -import { decodeSubscribeResponse, Subscribe } from "./subscribe.ts"; +import { + decodeSubscribeResponse, + encodeSubscribeResponse, + Subscribe, + SubscribeEnd, + SubscribeStart, +} from "./subscribe.ts"; +import { TrackInfo, Track as TrackMessage } from "./track.ts"; import { ALPN_04, ALPN_05, ALPN_06, ALPN_07_WIP, Version } from "./version.ts"; /** A transport whose `getStats` behaves as described, or is absent entirely. */ @@ -602,3 +610,51 @@ for (const [alpn, version] of [ } }); } + +// A group stream that breaks the protocol ends the session, so a hostile peer cannot repeat +// it on every stream. +for (const violation of ["a partial group", "a group past the declared end"] as const) { + test(`${violation} closes the session with PROTOCOL_VIOLATION`, async () => { + const version = Version.DRAFT_07; + const pair = createMockTransportPair(ALPN_07_WIP); + const connection = new Connection({ url: new URL("https://relay.example/"), quic: pair.client, version }); + try { + const track = wireOf(connection).consume(Path.from("room")).track("video").subscribe(); + + // The publisher, played by hand: answer TRACK_INFO, start the subscription, and + // leave any other stream the session opens (such as PROBE) open. + let sub: Stream | undefined; + while (!sub) { + const stream = await Stream.accept(pair.server, version); + if (!stream) throw new Error("the subscriber never subscribed"); + const id = await stream.reader.u53(); + if (id === StreamId.Track) { + await TrackMessage.decode(stream.reader, version); + await new TrackInfo({ maxAge: 60_000, timescale: Timescale.MILLI }).encode(stream.writer, version); + stream.close(); + } else if (id === StreamId.Subscribe) { + await Subscribe.decode(stream.reader, version); + sub = stream; + } + } + await encodeSubscribeResponse(sub.writer, { start: new SubscribeStart(0) }, version); + + let group: GroupMessage; + if (violation === "a partial group") { + // The subscriber never asked to start mid-group. + group = new GroupMessage({ subscribe: 0n, sequence: 0, frameStart: 5 }); + } else { + await encodeSubscribeResponse(sub.writer, { end: new SubscribeEnd(2) }, version); + group = new GroupMessage({ subscribe: 0n, sequence: 2 }); + } + const writer = await Writer.open(pair.server, { version }); + await writer.u53(DataType.Group); + await group.encode(writer, version); + + expect((await pair.client.closed).closeCode).toBe(SessionCode.ProtocolViolation); + track.close(); + } finally { + connection.abort(); + } + }); +} diff --git a/js/net/src/lite/subscriber.ts b/js/net/src/lite/subscriber.ts index 5e44ff3464f..5a2a9c8e8a1 100644 --- a/js/net/src/lite/subscriber.ts +++ b/js/net/src/lite/subscriber.ts @@ -1596,6 +1596,12 @@ export class Subscriber { const read = tail.open(group.sequence); try { + // This side never asks for a group from a later frame, so a stream that skips the + // first ones is a peer bug. Read as a whole group, its frames would be misnumbered, + // and resumption and deduplication rely on those positions. + if (group.frameStart !== 0) { + throw new ProtocolViolation(`group ${group.sequence} starts at frame ${group.frameStart}`); + } // The publisher contradicted its own end, which no later group can repair. lite-05 // specified an inclusive end, so its last group lands on it: the write below drops // only that group there. @@ -1622,14 +1628,17 @@ export class Subscriber { scale = timescale.peek(); } - const compress = entry.compress; - if (compress && group.frameStart !== 0) - throw new StreamError(StreamCode.TooFarBehind, { message: "compressed group lacks its prefix" }); - await readFrames(stream, producer, { scale, timed: hasMediaTime(this.version), compress }); + await readFrames(stream, producer, { scale, timed: hasMediaTime(this.version), compress: entry.compress }); producer.close(); stream.stop(StreamCode.Cancel); } catch (err: unknown) { + // A violation ends the session, which the connection does once it escapes; anything + // else ends only this group. + if (err instanceof ProtocolViolation) { + producer.close(err); + throw err; + } const e = await sessionCause(this.#quic, err); producer.close(e); stream.stop(e); diff --git a/js/net/src/lite/tail.test.ts b/js/net/src/lite/tail.test.ts index 160b258914d..88e2f7bed09 100644 --- a/js/net/src/lite/tail.test.ts +++ b/js/net/src/lite/tail.test.ts @@ -319,10 +319,18 @@ describe.each([Version.DRAFT_05, Version.DRAFT_06, Version.DRAFT_07])("%s", (ver await respond({ end: new SubscribeEnd(2) }); expect(await reader.finished()).toEqual({ group: 2, frame: 0 }); - await groupStream(subscriber, 2).handled; + const handled = groupStream(subscriber, 2).handled; if (version === Version.DRAFT_05) { + await handled; expect(await settlesWithin(Promise.resolve(reader.closed), 50)).toBe(false); } else { + // The violation escapes to the connection, which closes the session on it. + expect( + await handled.then( + () => undefined, + (err: unknown) => err, + ), + ).toBeInstanceOf(ProtocolViolation); expect(await reader.closed).toBeInstanceOf(ProtocolViolation); } }); diff --git a/quest/m1/release-audit/README.md b/quest/m1/release-audit/README.md index d87107521af..a59ebe6a833 100644 --- a/quest/m1/release-audit/README.md +++ b/quest/m1/release-audit/README.md @@ -83,7 +83,7 @@ network-impairment performance result is implied by these checks. ## Required -The 21 children comprise 17 reproduced or source-confirmed findings, three +The 20 children comprise 16 reproduced or source-confirmed findings, three contract/lifetime investigations, and one security-review pointer. Each child records whether its behavior is new on main or inherited from release. @@ -93,7 +93,6 @@ child records whether its behavior is new on main or inherited from release. - [Validate CMAF header fields](/quest/m1/release-audit/cmaf-counts.md) - tiny fragments cannot force allocations proportional to an untrusted sample count, and a zero timescale is refused - [Preserve fMP4 sample runs](/quest/m1/release-audit/fmp4-passthrough.md) - passthrough does not substitute gap or interleaved bytes for media samples - [JS honors subscription bounds](/quest/m1/release-audit/js-subscription-bounds.md) - each reader and each datagram stays inside its own subscription's group bounds, not the aggregate's -- [Refuse partial lite groups in JS](/quest/m1/release-audit/js-partial-group.md) - a nonzero `frameStart` closes the session as a protocol violation, not a renumbered complete group - [Announce finite HLS imports](/quest/m1/release-audit/hls-startup.md) - a completed valid source cannot race its ready catalog and fail startup - [Cancel Dart stream reads](/quest/m1/release-audit/dart-cancellation.md) - listener cancellation releases pending native operations without an unrelated event - [Parse QMux records without copying suffixes](/quest/m1/release-audit/qmux-copy.md) - many small frames do not cause quadratic copying diff --git a/quest/m1/release-audit/js-partial-group.md b/quest/m1/release-audit/js-partial-group.md deleted file mode 100644 index e666ce3b56c..00000000000 --- a/quest/m1/release-audit/js-partial-group.md +++ /dev/null @@ -1,35 +0,0 @@ -# [S] JS refuses an unrequested partial lite group - -## Goal - -A JS lite subscriber refuses a group stream whose `frameStart` is above 0 as a -protocol violation, closing the session, instead of exposing its first frame -as frame 0. - -## Plan - -P2, inherited from release (lite-06 added the field; JS parses and ignores -it). The 2026-10-22 subscription audit injected a lite-07 group declaring -`frameStart: 5` at main 1f5caa7026; its first frame read back as frame 0. The -group receiver in `js/net/src/lite/subscriber.ts` builds every group from -frame 0 and checks the offset only for compressed groups. A partial group then -looks complete, corrupting the frame positions resumption and deduplication -rely on. - -Decided 2026-10-22: refuse rather than model the offset. A JS subscriber never -asks for a mid-group start, so a nonzero `frameStart` is a peer bug. Raise -`ProtocolViolation`, folding the compressed-group check into the same rule. - -The violation must close the session, as `ProtocolViolation` promises, so a -hostile peer cannot repeat it on every stream (found in review of the planning -PR). Today `runGroup` catches every error, closes the group, resets the -stream, and returns, so nothing reaches the dispatch in `lite/connection.ts`. -The existing check for a group past the track's declared end throws the same -way and is swallowed too; fix both, letting the violation escape `runGroup` -while ordinary group errors stay stream-scoped. Test that each closes the -session. - -[JS ranges](/quest/m1/subscribe-ranges/js.md) carries the offset through the -group model when it adds frame bounds. - -Public API: none. Wire: none. diff --git a/quest/m1/subscribe-ranges/js.md b/quest/m1/subscribe-ranges/js.md index a6ff401a72d..7a747f51e3f 100644 --- a/quest/m1/subscribe-ranges/js.md +++ b/quest/m1/subscribe-ranges/js.md @@ -29,9 +29,8 @@ IETF FETCH dispatch. Resized from [M] to [L] for it. concurrent requests, and cancellation while awaiting a reply. When ranges add frame bounds, the group model carries a lite group's -`frameStart` instead of refusing a nonzero one, as -[partial lite groups](/quest/m1/release-audit/js-partial-group.md) does until -then. The group-bound rule itself, for reads and datagrams, lands first in +`frameStart` instead of refusing a nonzero one as a protocol violation, as +`lite/subscriber.ts` `runGroup` does until then. The group-bound rule itself, for reads and datagrams, lands first in [subscription bounds](/quest/m1/release-audit/js-subscription-bounds.md). ## Required @@ -41,4 +40,3 @@ then. The group-bound rule itself, for reads and datagrams, lands first in ## Related - [JS subscription bounds](/quest/m1/release-audit/js-subscription-bounds.md) - today's `groups` bounds enforced per reader and on datagrams -- [Partial lite groups](/quest/m1/release-audit/js-partial-group.md) - refuses a nonzero `frameStart` until this models it