Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
58 changes: 57 additions & 1 deletion js/net/src/lite/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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();
}
});
}
17 changes: 13 additions & 4 deletions js/net/src/lite/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,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.
Expand All @@ -1621,14 +1627,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);
Expand Down
10 changes: 9 additions & 1 deletion js/net/src/lite/tail.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
1 change: 0 additions & 1 deletion quest/m1/release-audit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ child records whether its behavior is new on main or inherited from release.
- [Review HLS admission](/quest/m1/release-audit/hls-admission.md) - resolve the security-sensitive resource-boundary review before the cut
- [Bound decoded datagram retention](/quest/m1/release-audit/datagram-memory.md) - shared ownership accounts for retained plain and compressed payloads across tracks
- [Decode order](/quest/m1/ts-reliability/decode-order.md) - the exporters' decode clock holds at most the declared reorder depth, so flat timestamps cannot bypass MKV/TS backpressure or cause quadratic draining
- [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
- [Parse QMux records without copying suffixes](/quest/m1/release-audit/qmux-copy.md) - many small frames do not cause quadratic copying
- [Release AUTH wake listeners](/quest/m1/release-audit/auth-listeners.md) - session churn does not retain one terminal promise reaction per change
- [Report fatal watch ingestion failures](/quest/m1/release-audit/watch-errors.md) - failed audio/video reads reach the existing error output and tear down their resources
Expand Down
35 changes: 0 additions & 35 deletions quest/m1/release-audit/js-partial-group.md

This file was deleted.

12 changes: 4 additions & 8 deletions quest/m1/subscribe-ranges/js.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,11 @@ 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. Preserve the per-reader group-bound rule for reliable reads, live-edge
selection, subscription updates, and publisher datagrams.
`frameStart` instead of refusing a nonzero one as a protocol violation, as
`lite/subscriber.ts` `runGroup` does until then. Preserve the per-reader
group-bound rule for reliable reads, live-edge selection, subscription
updates, and publisher datagrams.

## Required

- [Lite-07 ranges](/quest/m1/subscribe-ranges/lite.md) - the wire this speaks

## Related

- [Partial lite groups](/quest/m1/release-audit/js-partial-group.md) - refuses a nonzero `frameStart` until this models it
Loading