From 5e0b7684933d14119c0151e2b5918a62c7ffe486 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 7 Oct 2026 11:53:01 -0700 Subject: [PATCH 1/6] claim quest/m0/ietf-params-per-draft From f2977fcab0a361423b07bba770535132939b990a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 7 Oct 2026 12:54:56 -0700 Subject: [PATCH 2/6] fix(net): accept each draft's message parameters A parameter the draft defines for a message is decoded. A known parameter on a message that draft does not define is ignored through draft-16 and closes the session from draft-17 on. An unknown id still closes the session from draft-16 on. Draft-17 already closes on a known parameter used on the wrong message. Co-authored-by: Grok 4 --- js/net/src/ietf/cluster.ts | 2 +- js/net/src/ietf/fetch.ts | 2 +- js/net/src/ietf/ietf.test.ts | 58 ++++++ js/net/src/ietf/parameters.ts | 203 ++++++++++++++++++++- js/net/src/ietf/publish.ts | 6 +- js/net/src/ietf/publish_namespace.ts | 4 +- js/net/src/ietf/publisher.ts | 2 +- js/net/src/ietf/request.ts | 2 +- js/net/src/ietf/subscribe.ts | 8 +- js/net/src/ietf/subscribe_namespace.ts | 4 +- rs/moq-net/src/ietf/fetch.rs | 26 +-- rs/moq-net/src/ietf/parameters.rs | 127 +++++++++++-- rs/moq-net/src/ietf/publish.rs | 112 +++++++++--- rs/moq-net/src/ietf/request_stream.rs | 19 +- rs/moq-net/src/ietf/subscribe.rs | 127 +++++++------ rs/moq-net/src/ietf/subscribe_namespace.rs | 44 +++++ 16 files changed, 615 insertions(+), 131 deletions(-) diff --git a/js/net/src/ietf/cluster.ts b/js/net/src/ietf/cluster.ts index 9a77b3cea0b..da7c2024ade 100644 --- a/js/net/src/ietf/cluster.ts +++ b/js/net/src/ietf/cluster.ts @@ -215,7 +215,7 @@ function encodeHops(hops: Hop[]): Uint8Array { export async function decodeParams(r: Reader, version: IetfVersion): Promise { let params: Parameters; try { - params = await Parameters.decode(r, version); + params = await Parameters.decode(r, version, "namespace"); } catch (err) { throw new ProtocolViolation(reason(err), { cause: err }); } diff --git a/js/net/src/ietf/fetch.ts b/js/net/src/ietf/fetch.ts index e0a5159873f..3db0412c98a 100644 --- a/js/net/src/ietf/fetch.ts +++ b/js/net/src/ietf/fetch.ts @@ -89,7 +89,7 @@ export class Fetch { } } - const params = await Parameters.decode(r, version); + const params = await Parameters.decode(r, version, "fetch"); if (params.rangeFilters && !hasRangeFilters(version)) { throw new Error("Range Filters need draft-19"); } diff --git a/js/net/src/ietf/ietf.test.ts b/js/net/src/ietf/ietf.test.ts index 529eef1bde1..25b082f39e2 100644 --- a/js/net/src/ietf/ietf.test.ts +++ b/js/net/src/ietf/ietf.test.ts @@ -1,4 +1,5 @@ import { expect, test } from "bun:test"; +import { ProtocolViolation } from "../error.ts"; import * as Path from "../path.ts"; import { type Cursor, Reader, Writer } from "../stream.ts"; import { Timescale, Timestamp } from "../time.ts"; @@ -1559,6 +1560,63 @@ test("SubscribeNamespace: draft-18 omits subscribe options", async () => { } }); +// FORWARD is legal on SUBSCRIBE_NAMESPACE through draft-17. A value other than 0 or 1 +// still closes the session. Draft-18 dropped it from this message. +test("SubscribeNamespace: FORWARD follows the draft", async () => { + const legacy = (version: IetfVersion, value: number) => { + const body = [0x01]; + if (version === Version.DRAFT_17) body.push(0x00); + body.push(0x00, 0x01, 0x01, 0x10, value); + return framed(body); + }; + + for (const version of [Version.DRAFT_16, Version.DRAFT_17] as const) { + const decoded = await decodeVersioned( + legacy(version, 0), + SubscribeNamespace.SubscribeNamespaceLegacy.decode, + version, + ); + expect(decoded.requestId).toBe(1n); + await expect( + decodeVersioned(legacy(version, 2), SubscribeNamespace.SubscribeNamespaceLegacy.decode, version), + ).rejects.toThrow(ProtocolViolation); + } + + await expect( + decodeVersioned( + framed([0x01, 0x00, 0x01, 0x10, 0x00]), + SubscribeNamespace.SubscribeNamespace.decode, + Version.DRAFT_18, + ), + ).rejects.toThrow(ProtocolViolation); +}); + +// EXPIRES is a draft-16 message parameter, but not on SUBSCRIBE. Draft-16 ignores it and +// still reads the parameter after it. Draft-18 closes the session. +test("Parameters: a known parameter on the wrong message", async () => { + const block = new Uint8Array([0x02, 0x08, 0x05, 0x18, 0x07]); + const ignored = await Parameters.decode( + new Reader(undefined, block, Version.DRAFT_16), + Version.DRAFT_16, + "subscribe", + ); + expect(ignored.subscriberPriority).toBe(7); + expect(ignored.expires).toBeUndefined(); + + await expect( + Parameters.decode(new Reader(undefined, block, Version.DRAFT_18), Version.DRAFT_18, "subscribe"), + ).rejects.toThrow(ProtocolViolation); +}); + +test("Subscribe: SUBGROUP_DELIVERY_TIMEOUT follows its draft", async () => { + const body = framed([...TRACK_HEAD, 0x01, 0x06, 0x00]); + await expect(decodeVersioned(body, Subscribe.Subscribe.decode, Version.DRAFT_16)).rejects.toThrow( + ProtocolViolation, + ); + const decoded = await decodeVersioned(body, Subscribe.Subscribe.decode, Version.DRAFT_18); + expect(decoded.trackName).toBe("video"); +}); + test("Group: draft-18 sets FIRST_OBJECT bit, draft-17 does not", async () => { const makeGroup = () => new Group({ diff --git a/js/net/src/ietf/parameters.ts b/js/net/src/ietf/parameters.ts index 0530e279173..a756b2dd6e0 100644 --- a/js/net/src/ietf/parameters.ts +++ b/js/net/src/ietf/parameters.ts @@ -1,5 +1,7 @@ +import { ProtocolViolation } from "../error.ts"; import type { Reader, Writer } from "../stream.ts"; import * as Varint from "../varint.ts"; +import * as Namespace from "./namespace.ts"; import { type IetfVersion, Version } from "./version.ts"; /// Setup Option key constants (separate namespace from Message Parameters). @@ -222,6 +224,147 @@ const MSG_PARAM_SUBSCRIPTION_FILTER = 0x21n; const MSG_PARAM_FILL_PARAMETERS = 0x23n; /// HOP_PATH, from the MoQ Cluster extension. See `cluster.ts`. const MSG_PARAM_HOP_PATH = 0x40b57n; +/// TRACK_NAMESPACE_PREFIX (0x34). A Track Namespace tuple, not a varint. +const MSG_PARAM_TRACK_NAMESPACE_PREFIX = 0x34n; +/// ACTIVE_COUNT, from the MoQ Active Count extension. +const MSG_PARAM_ACTIVE_COUNT = 0x40b66n; + +/// Message parameter ids defined in draft-16. A known id on the wrong message is ignored. +const DRAFT16_MESSAGE_PARAMS: readonly bigint[] = [0x02n, 0x03n, 0x08n, 0x09n, 0x10n, 0x20n, 0x21n, 0x22n, 0x32n]; + +/** Which control message the parameter block belongs to. Omitted keeps the unfiltered decode. */ +type ControlMessage = + | "subscribe" + | "subscribe-ok" + | "subscribe-update" + | "subscribe-namespace" + | "publish" + | "publish-ok" + | "publish-namespace" + | "fetch" + | "fetch-ok" + | "request-ok" + | "request-update" + | "namespace"; + +function draft20(version: IetfVersion): boolean { + return version >= Version.DRAFT_20; +} + +/** True when this draft's definition of `message` includes `id`. */ +function allows(message: ControlMessage, version: IetfVersion, id: bigint): boolean { + const d15 = version === Version.DRAFT_15; + const d16 = version === Version.DRAFT_16; + const d17 = version === Version.DRAFT_17; + const d18 = version === Version.DRAFT_18; + const d19 = version === Version.DRAFT_19; + const from16 = version >= Version.DRAFT_16; + const from17 = version >= Version.DRAFT_17; + const from18 = version >= Version.DRAFT_18; + const from19 = version >= Version.DRAFT_19; + const legacyForward = d15 || d16 || d17; + const auth = id === MSG_PARAM_AUTHORIZATION_TOKEN; + const forward = id === MSG_PARAM_FORWARD; + const priority = id === MSG_PARAM_SUBSCRIBER_PRIORITY; + const filter = id === MSG_PARAM_SUBSCRIPTION_FILTER; + const order = id === MSG_PARAM_GROUP_ORDER; + const expires = id === MSG_PARAM_EXPIRES; + const largest = id === MSG_PARAM_LARGEST_OBJECT; + const objectTimeout = id === MSG_PARAM_DELIVERY_TIMEOUT; + const subgroupTimeout = id === MSG_PARAM_SUBGROUP_DELIVERY_TIMEOUT && from18; + const range = id >= 0x25n && id <= 0x28n && from19; + const trackRange = id === MSG_PARAM_TRACK_PROPERTY_FILTER && from19; + const fill = id === MSG_PARAM_FILL_PARAMETERS && draft20(version); + const include = id === MSG_PARAM_INCLUDE_PROPERTIES && draft20(version); + const newGroup = id === MSG_PARAM_NEW_GROUP_REQUEST && from16; + const prefix = id === MSG_PARAM_TRACK_NAMESPACE_PREFIX && from18; + + switch (message) { + case "subscribe": + return ( + objectTimeout || + auth || + (id === MSG_PARAM_MAX_CACHE_DURATION && from17) || + subgroupTimeout || + forward || + priority || + filter || + order || + fill || + range || + newGroup || + include + ); + case "subscribe-ok": + return (id === MSG_PARAM_MAX_CACHE_DURATION && d15) || expires || largest || (order && d15); + case "subscribe-update": + case "request-update": + return ( + objectTimeout || + auth || + subgroupTimeout || + forward || + priority || + filter || + fill || + range || + trackRange || + newGroup || + prefix + ); + case "subscribe-namespace": + return auth || (forward && legacyForward) || id === MSG_PARAM_HIDDEN; + case "publish": + return ( + (objectTimeout && (d15 || draft20(version))) || + auth || + (subgroupTimeout && draft20(version)) || + expires || + largest || + forward || + (priority && draft20(version)) || + (filter && draft20(version)) || + (order && (d15 || draft20(version))) + ); + case "publish-ok": + return ( + (objectTimeout && !draft20(version)) || + (id === MSG_PARAM_SUBGROUP_DELIVERY_TIMEOUT && (d18 || d19)) || + expires || + (forward && !draft20(version)) || + (priority && !draft20(version)) || + (filter && !draft20(version)) || + (order && (d15 || d16 || d17 || d18)) || + (id === MSG_PARAM_NEW_GROUP_REQUEST && (d16 || d17 || d18 || d19)) + ); + case "publish-namespace": + return auth || id === MSG_PARAM_HOP_PATH || id === MSG_PARAM_ROUTE_COST; + case "fetch": + return ( + auth || + (id === MSG_PARAM_FILL_TIMEOUT && from18) || + priority || + (filter && draft20(version)) || + order || + range || + include + ); + case "fetch-ok": + return (id === MSG_PARAM_MAX_CACHE_DURATION && d15) || (order && d15); + case "request-ok": + return expires || largest || id === MSG_PARAM_ACTIVE_COUNT; + case "namespace": + return id === MSG_PARAM_HOP_PATH || id === MSG_PARAM_ROUTE_COST; + } +} + +async function skipKvp(r: Reader, id: bigint): Promise { + if (id % 2n === 0n) { + await r.u62(); + } else { + await r.read(await r.u53()); + } +} /// The object Range Filters (draft-19): SUBGROUP, OBJECTID, PRIORITY and OBJECT_PROPERTY. /// Each is length prefixed whatever the parity of its id. @@ -250,6 +393,7 @@ function getMessageParamKind(id: bigint): MessageParamKind { case MSG_PARAM_EXPIRES: case MSG_PARAM_ROUTE_COST: case MSG_PARAM_HIDDEN: + case MSG_PARAM_ACTIVE_COUNT: return "varint"; case MSG_PARAM_PUBLISHER_PRIORITY: case MSG_PARAM_SUBSCRIBER_PRIORITY: @@ -570,7 +714,32 @@ export class Parameters { } } - static async decode(r: Reader, version: IetfVersion): Promise { + /** + * Decode a parameter block. + * + * `message`, when set, is the allow-list for that control message. A parameter the + * draft defines for a different message is ignored through draft-16 and closes the + * session from draft-17 on. An id the draft does not define at all closes from + * draft-16 on. Draft-14 and draft-15 ignore anything the message does not list. + * Omitting `message` keeps the previous decode, which stores every id. + */ + static async decode( + r: Reader, + version: IetfVersion, + message?: + | "subscribe" + | "subscribe-ok" + | "subscribe-update" + | "subscribe-namespace" + | "publish" + | "publish-ok" + | "publish-namespace" + | "fetch" + | "fetch-ok" + | "request-ok" + | "request-update" + | "namespace", + ): Promise { const count = await r.u53(); const params = new Parameters(); @@ -587,12 +756,35 @@ export class Parameters { prevType = id; } + if (message !== undefined && !allows(message, version, id)) { + // Draft-17 on has no length on a parameter value, so an unlisted id cannot be skipped. + const ignore = + version === Version.DRAFT_14 || + version === Version.DRAFT_15 || + (version === Version.DRAFT_16 && DRAFT16_MESSAGE_PARAMS.includes(id)); + if (!ignore) { + throw new ProtocolViolation(`message parameter ${id} is not defined for ${message}`); + } + await skipKvp(r, id); + continue; + } + + // Even id, but the value is a Track Namespace tuple rather than a varint. + if (id === MSG_PARAM_TRACK_NAMESPACE_PREFIX && version >= Version.DRAFT_17) { + await Namespace.decode(r); + continue; + } + if (version === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16) { if (id % 2n === 0n) { if (params.vars.has(id)) { throw new Error(`duplicate message parameter id: ${id.toString()}`); } const varint = await r.u62(); + // A bool is a varint here. Only 0 and 1 are legal once the message lists it. + if (message !== undefined && id === MSG_PARAM_FORWARD && varint !== 0n && varint !== 1n) { + throw new ProtocolViolation(`invalid message parameter value: ${id}`); + } params.vars.set(id, varint); } else { const size = await r.u53(); @@ -631,9 +823,14 @@ export class Parameters { case "uint8": params.vars.set(id, BigInt(await r.u8())); break; - case "bool": - params.vars.set(id, (await r.bool()) ? 1n : 0n); + case "bool": { + const value = await r.u8(); + if (value !== 0 && value !== 1) { + throw new ProtocolViolation(`invalid message parameter value: ${id}`); + } + params.vars.set(id, BigInt(value)); break; + } case "location": { // Two bare varints from draft-17 on; see the matching comment in encode. const groupId = await r.u62(); diff --git a/js/net/src/ietf/publish.ts b/js/net/src/ietf/publish.ts index dbe73ecf45d..19b1c94cd63 100644 --- a/js/net/src/ietf/publish.ts +++ b/js/net/src/ietf/publish.ts @@ -133,10 +133,10 @@ export class Publish { }); } // v15+: parameters followed by Track Properties (draft-17+) - const params = await Parameters.decode(r, version); + const params = await Parameters.decode(r, version, "publish"); const properties = await Properties.decode(r, version); - // GROUP_ORDER is only legal here through draft-15, but keep accepting it so a peer that - // still sends it doesn't have its session torn down over a hint. + // GROUP_ORDER is legal here in draft-15 and again from draft-20. Draft-16 ignores it. + // Draft-17 through draft-19 close the session. const groupOrder = properties.groupOrder ?? params.groupOrder ?? 0x02; const forward = params.forward ?? true; const largest = params.largest; diff --git a/js/net/src/ietf/publish_namespace.ts b/js/net/src/ietf/publish_namespace.ts index 1be3e59c458..a53a82ab803 100644 --- a/js/net/src/ietf/publish_namespace.ts +++ b/js/net/src/ietf/publish_namespace.ts @@ -66,7 +66,7 @@ export class PublishNamespace { return new PublishNamespace({ requestId, trackNamespace, cluster }); } - await Parameters.decode(r, version); // ignore parameters + await Parameters.decode(r, version, "publish-namespace"); return new PublishNamespace({ requestId, trackNamespace }); } } @@ -134,7 +134,7 @@ export class PublishNamespaceUpdate { if (version === Version.DRAFT_17) { await r.u62(); // required_request_id_delta (draft-17 only, removed in draft-18 per #1615) } - const params = await Parameters.decode(r, version); + const params = await Parameters.decode(r, version, "publish-namespace"); return new PublishNamespaceUpdate({ requestId, update: Cluster.updateFromParams(params) }); } } diff --git a/js/net/src/ietf/publisher.ts b/js/net/src/ietf/publisher.ts index 941b6ba67a3..1d9119d9bb8 100644 --- a/js/net/src/ietf/publisher.ts +++ b/js/net/src/ietf/publisher.ts @@ -463,7 +463,7 @@ export class Publisher { const params = await Message.decode(stream.reader, async (r) => { await r.u62(); if (version === Version.DRAFT_17) await r.u62(); - return Parameters.decode(r, version); + return Parameters.decode(r, version, "request-update"); }); const unsupported = params.forward === false || diff --git a/js/net/src/ietf/request.ts b/js/net/src/ietf/request.ts index 926721c969c..01547081196 100644 --- a/js/net/src/ietf/request.ts +++ b/js/net/src/ietf/request.ts @@ -86,7 +86,7 @@ export class RequestOk { version === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16 ? await r.u62() : undefined; - const parameters = await Parameters.decode(r, version); + const parameters = await Parameters.decode(r, version, "request-ok"); await Properties.decode(r, version); return new RequestOk({ requestId, parameters }); } diff --git a/js/net/src/ietf/subscribe.ts b/js/net/src/ietf/subscribe.ts index fcd48f42607..73d218463ae 100644 --- a/js/net/src/ietf/subscribe.ts +++ b/js/net/src/ietf/subscribe.ts @@ -150,7 +150,7 @@ export class Subscribe { return new Subscribe({ requestId, trackNamespace, trackName, subscriberPriority, filter, forward }); } // v15+: fields are in parameters - const params = await Parameters.decode(r, version); + const params = await Parameters.decode(r, version, "subscribe"); const subscriberPriority = params.subscriberPriority ?? 128; let groupOrder = params.groupOrder ?? GROUP_ORDER; if (groupOrder > 2) { @@ -306,7 +306,7 @@ export class SubscribeOk { // v15+: parameters followed by Track Properties (draft-17+). LARGEST_OBJECT is // required on every draft once the track has content, so rejecting it would tear // down a session over a parameter compliant publishers must send. - const params = await Parameters.decode(r, version); + const params = await Parameters.decode(r, version, "subscribe-ok"); largest = params.largest; properties = await Properties.decode(r, version); if (version === Version.DRAFT_15) properties.maxCacheDuration = params.maxCacheDuration; @@ -413,7 +413,7 @@ export class SubscribeUpdate { } else if (version === Version.DRAFT_15 || version === Version.DRAFT_16) { const requestId = await r.u62(); await r.u62(); // subscription_request_id - await Parameters.decode(r, version); + await Parameters.decode(r, version, "subscribe-update"); return new SubscribeUpdate({ requestId }); } else { // v17+: REQUEST_UPDATE @@ -421,7 +421,7 @@ export class SubscribeUpdate { if (version === Version.DRAFT_17) { await r.u62(); // required_request_id_delta (draft-17 only, removed in draft-18 per #1615) } - await Parameters.decode(r, version); + await Parameters.decode(r, version, "subscribe-update"); return new SubscribeUpdate({ requestId }); } } diff --git a/js/net/src/ietf/subscribe_namespace.ts b/js/net/src/ietf/subscribe_namespace.ts index a36090c910e..d087690a1c7 100644 --- a/js/net/src/ietf/subscribe_namespace.ts +++ b/js/net/src/ietf/subscribe_namespace.ts @@ -68,7 +68,7 @@ export class SubscribeNamespace { } const requestId = await r.u62(); const namespace = await Namespace.decode(r); - const params = await Parameters.decode(r, version); + const params = await Parameters.decode(r, version, "subscribe-namespace"); return new SubscribeNamespace({ namespace, requestId, hidden: params.hidden }); } @@ -144,7 +144,7 @@ export class SubscribeNamespaceLegacy { if (version === Version.DRAFT_16 || version === Version.DRAFT_17) { subscribeOptions = await r.u53(); } - const params = await Parameters.decode(r, version); + const params = await Parameters.decode(r, version, "subscribe-namespace"); return new SubscribeNamespaceLegacy({ namespace, requestId, subscribeOptions, hidden: params.hidden }); } diff --git a/rs/moq-net/src/ietf/fetch.rs b/rs/moq-net/src/ietf/fetch.rs index 0a50802c150..68f1da10d1f 100644 --- a/rs/moq-net/src/ietf/fetch.rs +++ b/rs/moq-net/src/ietf/fetch.rs @@ -204,13 +204,13 @@ impl Message for Fetch<'_> { let fetch_type = FetchType::decode(buf, version)?; decode_params!(buf, version, 0x03 => _authorization_token: Vec, - 0x0A => fill_timeout: Option, + 0x0A => fill_timeout: Option where !matches!(version, Version::Draft15 | Version::Draft16 | Version::Draft17), 0x20 => subscriber_priority: Option, 0x22 => group_order: Option, - 0x25 => subgroup_filter: Vec, - 0x26 => object_id_filter: Vec, - 0x27 => priority_filter: Vec, - 0x28 => object_property_filter: Vec, + 0x25 => subgroup_filter: Vec where has_range_filters(version), + 0x26 => object_id_filter: Vec where has_range_filters(version), + 0x27 => priority_filter: Vec where has_range_filters(version), + 0x28 => object_property_filter: Vec where has_range_filters(version), ); let range_filters = [ subgroup_filter, @@ -221,10 +221,9 @@ impl Message for Fetch<'_> { .iter() .any(|filter| !filter.is_empty()); - // An unknown message parameter is a protocol violation, so each stays rejected - // on the drafts that predate it: FILL_TIMEOUT arrived in draft-18. - let has_fill_timeout = !matches!(version, Version::Draft15 | Version::Draft16 | Version::Draft17); - if (fill_timeout.is_some() && !has_fill_timeout) || (range_filters && !has_range_filters(version)) { + // Range Filters arrived in draft-19. An earlier draft-16+ peer sending one + // is an unknown parameter. Draft-15 ignores an unrecognized parameter. + if range_filters && !has_range_filters(version) { return Err(DecodeError::InvalidValue); } @@ -358,11 +357,12 @@ impl Message for FetchOk { _ => { let end_of_track = buf.bool()?; let end_location = Location::decode(buf, version)?; - // GROUP_ORDER isn't legal here, but keep accepting it so a peer that still sends - // it doesn't have its session torn down over a hint. + // MAX_CACHE_DURATION and GROUP_ORDER are legal on FETCH_OK only in draft-15. + // Draft-16 still knows GROUP_ORDER, so one here is ignored. From draft-17 + // it closes the session. decode_params!(buf, version, - 0x04 => max_cache_duration: Option, - 0x22 => group_order: Option, + 0x04 => max_cache_duration: Option where version == Version::Draft15, + 0x22 => group_order: Option where version == Version::Draft15, ); // The timescale is read but not surfaced yet: a fetched object without an // interpretable timestamp is stamped on arrival. diff --git a/rs/moq-net/src/ietf/parameters.rs b/rs/moq-net/src/ietf/parameters.rs index a9a63b9c97d..79fc75f1d3f 100644 --- a/rs/moq-net/src/ietf/parameters.rs +++ b/rs/moq-net/src/ietf/parameters.rs @@ -413,6 +413,63 @@ impl Param for Opaque { } } +/// TRACK_NAMESPACE_PREFIX (0x34). The value is a Track Namespace tuple, not a varint, +/// so it has to be consumed or the parameters after it land on the wrong bytes. The +/// prefix itself is not applied: this message cannot say which request it updates. +#[derive(Clone, Debug, PartialEq, Eq)] +pub(crate) struct TrackNamespace { + pub(crate) path: crate::Path<'static>, +} + +impl Param for TrackNamespace { + fn param_encode(&self, w: &mut Encoder<'_>, _: Version) -> Result<(), EncodeError> { + super::namespace::encode_namespace(w, &self.path) + } + + fn param_decode(r: &mut Decoder<'_>, _: Version) -> Result { + Ok(Self { + path: super::namespace::decode_namespace(r)?, + }) + } +} + +/// Message parameter ids defined in draft-16. Sorted for `binary_search`. +/// +/// A known id on a message that does not list it is ignored. An id outside this set +/// is unknown and closes the session. +const DRAFT16_MESSAGE_PARAMS: &[u64] = &[0x02, 0x03, 0x08, 0x09, 0x10, 0x20, 0x21, 0x22, 0x32]; + +fn skip_kvp(r: &mut Decoder<'_>, key: u64) -> Result<(), DecodeError> { + if key.is_multiple_of(2) { + r.varint()?; + } else { + let value = r.bytes()?; + if value.len() > MAX_KVP_VALUE_LEN { + return Err(DecodeError::BoundsExceeded); + } + } + Ok(()) +} + +/// Consumes a parameter the message does not list, when that draft says to ignore it. +/// +/// Draft-14 and draft-15 ignore an unrecognized parameter, including one defined for a +/// different message. Draft-16 ignores a known parameter on the wrong message and closes +/// on an unknown id. From draft-17 on both close the session, and a parameter value has +/// no length to skip by, so this returns false and the caller fails the message. +pub(crate) fn skip_unlisted(r: &mut Decoder<'_>, version: Version, key: u64) -> Result { + let ignore = match version { + Version::Draft14 | Version::Draft15 => true, + Version::Draft16 => DRAFT16_MESSAGE_PARAMS.binary_search(&key).is_ok(), + _ => false, + }; + if !ignore { + return Ok(false); + } + skip_kvp(r, key)?; + Ok(true) +} + /// Encode message parameters with compile-time sorted keys. /// /// Keys must be listed in ascending order (enforced at compile time). @@ -470,7 +527,10 @@ macro_rules! encode_params { /// optional parameters (defaults to `None` when absent) and bare types like `u8` /// for parameters where `T::default()` is an acceptable fallback. /// -/// Unknown parameters cause `DecodeError::InvalidValue`. +/// A `where` gate takes the key off the list on versions where the expression is false. +/// What remains unlisted is ignored on draft-14 and draft-15, ignored on draft-16 when +/// the id is a message parameter of that draft used on the wrong message, and a +/// `DecodeError::InvalidValue` otherwise (unknown id, or any unlisted id from draft-17 on). /// Duplicate parameters cause `DecodeError::Duplicate`, unless the type allows a repeat /// (see [`Param::param_repeat`]), such as `Vec`. /// @@ -483,7 +543,7 @@ macro_rules! encode_params { /// let subscriber_priority = subscriber_priority.unwrap_or(128); /// ``` macro_rules! decode_params { - ($r:expr, $version:expr, $($key:expr => $name:ident: $ty:ty),* $(,)?) => { + ($r:expr, $version:expr, $($key:expr => $name:ident: $ty:ty $(where $gate:expr)?),* $(,)?) => { #[allow(unused)] const _: () = { let _keys: &[u64] = &[$($key),*]; @@ -517,8 +577,10 @@ macro_rules! decode_params { // An if-chain rather than a `match`, so a key can be a named constant: // the macro captures it as an expression, which is not a legal pattern. + // A false `where` gate falls through, so the draft's ignore-or-close rule applies + // instead of validating a value the message is not allowed to carry. $( - if _key == $key { + if _key == $key $( && ($gate) )? { let _value = <$ty as $crate::ietf::Param>::param_decode($r, _version)?; $name = Some(match $name.take() { None => _value, @@ -527,6 +589,9 @@ macro_rules! decode_params { continue; } )* + if $crate::ietf::parameters::skip_unlisted($r, _version, _key)? { + continue; + } return Err($crate::coding::DecodeError::InvalidValue); } } @@ -949,7 +1014,8 @@ mod tests { #[test] fn test_param_unknown_rejected() { - // Manually encode one param at key 0x10, try to decode expecting key 0x20 + // 0x3E is not a message parameter in any of these drafts. Draft-14 and draft-15 + // ignore it. Draft-16 on closes the session. for version in [ Version::Draft14, Version::Draft15, @@ -960,19 +1026,54 @@ mod tests { let mut buf = Vec::new(); let mut w = Encoder::new(&mut buf, version.into()); w.varint(1).unwrap(); - w.varint(0x10u64).unwrap(); - true.param_encode(&mut w, version).unwrap(); + w.varint(0x3Eu64).unwrap(); + 1u64.param_encode(&mut w, version).unwrap(); let mut bytes = Decoder::new(&buf, version.into()); - let result: Result<(), DecodeError> = (|| { + let result: Result, DecodeError> = (|| { decode_params!(&mut bytes, version, 0x20 => val: Option); - let _ = val; - Ok(()) + Ok(val) })(); - assert!( - matches!(result, Err(DecodeError::InvalidValue)), - "expected InvalidValue for unknown param in {version}" - ); + match version { + Version::Draft14 | Version::Draft15 => { + assert_eq!(result.unwrap(), None, "{version} ignores an unrecognized parameter"); + assert!(bytes.is_empty(), "{version}"); + } + _ => assert!( + matches!(result, Err(DecodeError::InvalidValue)), + "expected InvalidValue for unknown param in {version}" + ), + } + } + } + + /// EXPIRES (0x08) is a draft-16 message parameter, but not for a message whose list is + /// only SUBSCRIBER_PRIORITY. Draft-16 ignores it and still reads the parameter after it. + /// Draft-18 closes the session on the same bytes. + #[test] + fn known_param_on_the_wrong_message() { + for version in [Version::Draft16, Version::Draft18] { + let mut buf = Vec::new(); + let mut w = Encoder::new(&mut buf, version.into()); + w.varint(2).unwrap(); + w.varint(0x08u64).unwrap(); + 5u64.param_encode(&mut w, version).unwrap(); + w.varint(0x18u64).unwrap(); // delta from 0x08 to 0x20 + 7u8.param_encode(&mut w, version).unwrap(); + + let mut bytes = Decoder::new(&buf, version.into()); + let result: Result, DecodeError> = (|| { + decode_params!(&mut bytes, version, 0x20 => val: Option); + Ok(val) + })(); + match version { + Version::Draft16 => { + assert_eq!(result.unwrap(), Some(7)); + assert!(bytes.is_empty()); + } + Version::Draft18 => assert!(matches!(result, Err(DecodeError::InvalidValue))), + _ => unreachable!(), + } } } diff --git a/rs/moq-net/src/ietf/publish.rs b/rs/moq-net/src/ietf/publish.rs index 1cf60241eed..a2b071f3cbb 100644 --- a/rs/moq-net/src/ietf/publish.rs +++ b/rs/moq-net/src/ietf/publish.rs @@ -328,36 +328,26 @@ impl Message for Publish<'_> { }) } _ => { - // GROUP_ORDER is only legal here through draft-15, but keep accepting it so a - // peer that still sends it doesn't have its session torn down over a hint. + // GROUP_ORDER is legal on PUBLISH in draft-15 and again from draft-20, when + // the subscription parameters moved here. Draft-16 still knows the id, so one + // on this message is ignored. Draft-17 through draft-19 close the session. // - // Draft-20 moved the subscription parameters into PUBLISH, so they have to - // parse here even though reverse publishing is unsupported: an unlisted - // parameter fails the whole message, which would kill the session instead of - // letting the request reach its NOT_SUPPORTED response. + // The draft-20 parameters have to parse even though reverse publishing is + // unsupported: an unlisted parameter fails the whole message, which would + // kill the session instead of letting the request reach NOT_SUPPORTED. + // OBJECT_DELIVERY_TIMEOUT is also legal in draft-15. The values are dropped. decode_params!(r, version, - 0x02 => object_delivery_timeout: Option, + 0x02 => _object_delivery_timeout: Option where version == Version::Draft15 || Filter::is_draft20(version), 0x03 => _authorization_token: Vec, - 0x06 => subgroup_delivery_timeout: Option, + 0x06 => _subgroup_delivery_timeout: Option where Filter::is_draft20(version), 0x08 => _expires: Option, 0x09 => largest_location: Option, 0x10 => forward: Option, - 0x20 => subscriber_priority: Option, - 0x21 => filter: Option, - 0x22 => group_order: Option, + 0x20 => _subscriber_priority: Option where Filter::is_draft20(version), + 0x21 => _filter: Option where Filter::is_draft20(version), + 0x22 => group_order: Option where version == Version::Draft15 || Filter::is_draft20(version), ); - // The values are dropped: we refuse the PUBLISH itself, so the subscription - // settings it proposes never take effect. They still have to be consumed. - let subscription_params = [ - object_delivery_timeout.is_some(), - subgroup_delivery_timeout.is_some(), - subscriber_priority.is_some(), - filter.is_some(), - ]; - if subscription_params.contains(&true) && !Filter::is_draft20(version) { - return Err(DecodeError::InvalidValue); - } let mut properties = Properties::decode(r, version)?; properties.group_order = properties.group_order.or(group_order); @@ -414,11 +404,18 @@ impl Message for PublishOk { // PUBLISH and REQUEST_UPDATE now, so a PUBLISH_OK carries none of them. _ if Filter::is_draft20(version) => encode_params!(w, version,), _ => { + // GROUP_ORDER left PUBLISH_OK in draft-19. Sending it there is a parameter + // on the wrong message, which closes the session. + let group_order = matches!( + version, + Version::Draft15 | Version::Draft16 | Version::Draft17 | Version::Draft18 + ) + .then_some(self.group_order); encode_params!(w, version, 0x10 => self.forward, 0x20 => self.subscriber_priority, 0x21 => self.filter, - 0x22 => self.group_order, + 0x22 => group_order, ); } } @@ -452,13 +449,20 @@ impl Message for PublishOk { }) } _ => { - // EXPIRES is ignored, as in SUBSCRIBE_OK. + // EXPIRES is ignored, as in SUBSCRIBE_OK. Delivery timeouts and + // NEW_GROUP_REQUEST are legal on the drafts that list them and dropped: + // nothing here acts on a publisher's timeout. Draft-20 moved the + // subscription parameters off PUBLISH_OK, and draft-19 already dropped + // GROUP_ORDER. decode_params!(r, version, + 0x02 => _delivery_timeout: Option where !Filter::is_draft20(version), + 0x06 => _subgroup_delivery_timeout: Option where matches!(version, Version::Draft18 | Version::Draft19), 0x08 => _expires: Option, - 0x10 => forward: Option, - 0x20 => subscriber_priority: Option, - 0x21 => filter: Option, - 0x22 => group_order: Option, + 0x10 => forward: Option where !Filter::is_draft20(version), + 0x20 => subscriber_priority: Option where !Filter::is_draft20(version), + 0x21 => filter: Option where !Filter::is_draft20(version), + 0x22 => group_order: Option where matches!(version, Version::Draft15 | Version::Draft16 | Version::Draft17 | Version::Draft18), + 0x32 => _new_group_request: Option where matches!(version, Version::Draft16 | Version::Draft17 | Version::Draft18 | Version::Draft19), ); let forward = forward.unwrap_or(true); @@ -696,6 +700,58 @@ mod tests { assert_eq!(decoded.subscriber_priority, 128); } + fn publish_with_param(version: Version, key: u64, value: u64) -> Vec { + let mut buf = Vec::new(); + let w = &mut Encoder::new(&mut buf, version.into()); + RequestId(1).encode(w, version).unwrap(); + if version == Version::Draft17 { + w.varint(0).unwrap(); + } + encode_namespace(w, &Path::new("t")).unwrap(); + w.string("v").unwrap(); + w.varint(1).unwrap(); + w.varint(1).unwrap(); + w.varint(key).unwrap(); + w.varint(value).unwrap(); + buf + } + + fn publish_ok_with_param(version: Version, key: u64, value: u64) -> Vec { + let mut buf = Vec::new(); + let w = &mut Encoder::new(&mut buf, version.into()); + if matches!(version, Version::Draft14 | Version::Draft15 | Version::Draft16) { + RequestId(1).encode(w, version).unwrap(); + } + w.varint(1).unwrap(); + w.varint(key).unwrap(); + w.varint(value).unwrap(); + buf + } + + /// SUBSCRIBER_PRIORITY is known in draft-16 but not defined for PUBLISH until draft-20. + /// OBJECT_DELIVERY_TIMEOUT is legal on PUBLISH again from draft-20. + #[test] + fn publish_parameters_follow_the_draft() { + decode_message::(&publish_with_param(Version::Draft16, 0x20, 1), Version::Draft16) + .expect("draft-16 ignores SUBSCRIBER_PRIORITY"); + assert!(decode_message::(&publish_with_param(Version::Draft18, 0x20, 1), Version::Draft18).is_err()); + decode_message::(&publish_with_param(Version::Draft20, 0x02, 1), Version::Draft20) + .expect("draft-20 accepts OBJECT_DELIVERY_TIMEOUT"); + } + + /// PUBLISH_OK carries the delivery timeout through draft-19, and NEW_GROUP_REQUEST from + /// draft-16 through draft-19. Draft-20 no longer carries FORWARD. + #[test] + fn publish_ok_parameters_follow_the_draft() { + decode_message::(&publish_ok_with_param(Version::Draft19, 0x02, 1), Version::Draft19) + .expect("draft-19 accepts DELIVERY_TIMEOUT"); + decode_message::(&publish_ok_with_param(Version::Draft16, 0x32, 1), Version::Draft16) + .expect("draft-16 accepts NEW_GROUP_REQUEST"); + assert!( + decode_message::(&publish_ok_with_param(Version::Draft20, 0x10, 0), Version::Draft20).is_err() + ); + } + #[test] fn test_publish_done_registered_statuses_all_versions() { for version in [ diff --git a/rs/moq-net/src/ietf/request_stream.rs b/rs/moq-net/src/ietf/request_stream.rs index ddcfce1e8bd..b1b030c92ce 100644 --- a/rs/moq-net/src/ietf/request_stream.rs +++ b/rs/moq-net/src/ietf/request_stream.rs @@ -55,17 +55,20 @@ impl crate::coding::Decode for Update { decode_params!(&mut data, version, 0x02 => object_timeout: Option, 0x03 => token: Vec, - 0x06 => subgroup_timeout: Option, + 0x06 => subgroup_timeout: Option where !matches!(version, Version::Draft14 | Version::Draft15 | Version::Draft16 | Version::Draft17), 0x10 => forward: Option, 0x20 => priority: Option, 0x21 => filter: Option, - 0x23 => fill: Option, - 0x25 => subgroup_filter: Vec, - 0x26 => object_filter: Vec, - 0x27 => priority_filter: Vec, - 0x28 => property_filter: Vec, - 0x29 => track_filter: Vec, - 0x32 => new_group: Option, + 0x23 => fill: Option where Filter::is_draft20(version), + 0x25 => subgroup_filter: Vec where super::subscribe::has_range_filters(version), + 0x26 => object_filter: Vec where super::subscribe::has_range_filters(version), + 0x27 => priority_filter: Vec where super::subscribe::has_range_filters(version), + 0x28 => property_filter: Vec where super::subscribe::has_range_filters(version), + 0x29 => track_filter: Vec where super::subscribe::has_range_filters(version), + 0x32 => new_group: Option where !matches!(version, Version::Draft14 | Version::Draft15), + // Legal on a SUBSCRIBE_NAMESPACE update from draft-18. The message cannot + // say which request it updates, so the prefix is consumed and not applied. + 0x34 => _prefix: Option where !matches!(version, Version::Draft14 | Version::Draft15 | Version::Draft16 | Version::Draft17), ); if !data.is_empty() { return Err(DecodeError::InvalidValue); diff --git a/rs/moq-net/src/ietf/subscribe.rs b/rs/moq-net/src/ietf/subscribe.rs index 19d4e764420..6df3e47df11 100644 --- a/rs/moq-net/src/ietf/subscribe.rs +++ b/rs/moq-net/src/ietf/subscribe.rs @@ -91,19 +91,21 @@ impl Message for Subscribe<'_> { decode_params!(r, version, 0x02 => _object_delivery_timeout: Option, 0x03 => _authorization_token: Vec, - 0x04 => rendezvous_timeout: Option, - 0x06 => _subgroup_delivery_timeout: Option, + // 0x04 is MAX_CACHE_DURATION in draft-15 (a publisher parameter) and not a + // message parameter at all in draft-16. RENDEZVOUS_TIMEOUT arrives in draft-17. + 0x04 => rendezvous_timeout: Option where !matches!(version, Version::Draft15 | Version::Draft16), + 0x06 => _subgroup_delivery_timeout: Option where !matches!(version, Version::Draft14 | Version::Draft15 | Version::Draft16 | Version::Draft17), 0x10 => forward: Option, 0x20 => subscriber_priority: Option, 0x21 => filter: Option, 0x22 => group_order: Option, - 0x23 => fill: Option, - 0x25 => subgroup_filter: Vec, - 0x26 => object_id_filter: Vec, - 0x27 => priority_filter: Vec, - 0x28 => object_property_filter: Vec, - 0x32 => new_group_request: Option, - 0x35 => include_properties: Option, + 0x23 => fill: Option where Filter::is_draft20(version), + 0x25 => subgroup_filter: Vec where has_range_filters(version), + 0x26 => object_id_filter: Vec where has_range_filters(version), + 0x27 => priority_filter: Vec where has_range_filters(version), + 0x28 => object_property_filter: Vec where has_range_filters(version), + 0x32 => new_group_request: Option where has_new_group_request(version), + 0x35 => include_properties: Option where Filter::is_draft20(version), ); let range_filters = [ @@ -115,8 +117,9 @@ impl Message for Subscribe<'_> { .iter() .any(|filter| !filter.is_empty()); - // An unknown message parameter is a protocol violation, so each stays rejected - // on the drafts that predate it rather than being quietly tolerated. + // A parameter that arrived in a later draft is unknown from draft-16 on, which + // closes the session. The gates above are what reject it. Draft-14 and draft-15 + // ignore an unrecognized parameter instead, so it never reaches these checks. if ((fill.is_some() || include_properties.is_some()) && !Filter::is_draft20(version)) || (range_filters && !has_range_filters(version)) || (new_group_request.is_some() && !has_new_group_request(version)) @@ -127,13 +130,6 @@ impl Message for Subscribe<'_> { // Defaults to 1, so an absent parameter means the subscriber wants them. let properties_wanted = include_properties.unwrap_or(true); - // RENDEZVOUS_TIMEOUT arrived in draft-17; 0x04 means MAX_CACHE_DURATION in - // draft-15, which is a publisher parameter with no business in a SUBSCRIBE. - // An unknown message parameter is a protocol violation, so reject it there. - if rendezvous_timeout.is_some() && matches!(version, Version::Draft15 | Version::Draft16) { - return Err(DecodeError::InvalidValue); - } - // The value is deliberately dropped: we always answer a SUBSCRIBE with what is // published right now, which is the shorter timeout the draft lets a relay pick. // We still have to parse it, or the parameter alone would kill the session. @@ -293,16 +289,16 @@ impl Message for SubscribeOk { properties.max_cache_duration = Parameters::skip(r)?.map(std::time::Duration::from_millis); } _ => { - // GROUP_ORDER is only legal here through draft-15, but keep accepting it so a - // peer that still sends it doesn't have its session torn down over a hint. - // LARGEST_OBJECT is required on every draft once the track has content, so - // rejecting it would tear down a session over a parameter compliant - // publishers must send. EXPIRES is ignored, as on draft-14. + // GROUP_ORDER and MAX_CACHE_DURATION are legal here only in draft-15. Draft-16 + // still knows GROUP_ORDER, so one on this message is ignored. From draft-17 + // it closes the session. LARGEST_OBJECT is required once the track has + // content, so rejecting it would tear down a session over a parameter + // compliant publishers must send. EXPIRES is ignored, as on draft-14. decode_params!(r, version, - 0x04 => max_cache_duration: Option, + 0x04 => max_cache_duration: Option where version == Version::Draft15, 0x08 => _expires: Option, 0x09 => largest: Option, - 0x22 => group_order: Option, + 0x22 => group_order: Option where version == Version::Draft15, ); properties = Properties::decode(r, version)?; properties.group_order = properties.group_order.or(group_order); @@ -464,11 +460,10 @@ impl Message for SubscribeUpdate { decode_params!(r, version, 0x02 => _object_delivery_timeout: Option, 0x03 => _authorization_token: Vec, - 0x06 => _subgroup_delivery_timeout: Option, 0x10 => forward: Option, 0x20 => subscriber_priority: Option, 0x21 => _filter: Option, - 0x32 => new_group_request: Option, + 0x32 => new_group_request: Option where has_new_group_request(version), ); // NEW_GROUP_REQUEST arrived in draft-16. @@ -495,22 +490,25 @@ impl Message for SubscribeUpdate { let _required_request_id_delta = r.varint()?; } // Nothing reads an update's Range Filters yet; they are consumed so a legal - // update does not fail the session. TRACK_PROPERTY_FILTER (0x29) is legal - // only on an update to SUBSCRIBE_TRACKS, which the message alone can't tell. + // update does not fail the session. TRACK_PROPERTY_FILTER (0x29) and + // TRACK_NAMESPACE_PREFIX (0x34) are legal only on some request types, which + // the message alone can't tell, so a legal update is accepted and the value + // is not applied. decode_params!(r, version, 0x02 => _object_delivery_timeout: Option, 0x03 => _authorization_token: Vec, - 0x06 => _subgroup_delivery_timeout: Option, + 0x06 => _subgroup_delivery_timeout: Option where !matches!(version, Version::Draft14 | Version::Draft15 | Version::Draft16 | Version::Draft17), 0x10 => forward: Option, 0x20 => subscriber_priority: Option, 0x21 => _filter: Option, - 0x23 => fill: Option, - 0x25 => subgroup_filter: Vec, - 0x26 => object_id_filter: Vec, - 0x27 => priority_filter: Vec, - 0x28 => object_property_filter: Vec, - 0x29 => track_property_filter: Vec, + 0x23 => fill: Option where Filter::is_draft20(version), + 0x25 => subgroup_filter: Vec where has_range_filters(version), + 0x26 => object_id_filter: Vec where has_range_filters(version), + 0x27 => priority_filter: Vec where has_range_filters(version), + 0x28 => object_property_filter: Vec where has_range_filters(version), + 0x29 => track_property_filter: Vec where has_range_filters(version), 0x32 => _new_group_request: Option, + 0x34 => _prefix: Option where !matches!(version, Version::Draft14 | Version::Draft15 | Version::Draft16 | Version::Draft17), ); let range_filters = [ @@ -645,14 +643,15 @@ mod tests { } } - /// 0x04 only means RENDEZVOUS_TIMEOUT from draft-17 on; in draft-15 it is - /// MAX_CACHE_DURATION, a publisher parameter that has no business in a SUBSCRIBE. + /// 0x04 is MAX_CACHE_DURATION in draft-15, defined for other messages, so a SUBSCRIBE + /// that carries it is ignored. Draft-16 dropped the id, which makes it unknown. #[test] - fn rendezvous_timeout_is_rejected_before_draft17() { - for version in [Version::Draft15, Version::Draft16] { - let encoded = subscribe_with_rendezvous(0, version); - decode_message::(&encoded, version).expect_err(&format!("{version} must reject parameter 0x04")); - } + fn cache_duration_on_subscribe_follows_the_draft() { + let draft15 = subscribe_with_rendezvous(0, Version::Draft15); + decode_message::(&draft15, Version::Draft15).expect("draft-15 ignores MAX_CACHE_DURATION"); + + let draft16 = subscribe_with_rendezvous(0, Version::Draft16); + decode_message::(&draft16, Version::Draft16).expect_err("draft-16 rejects unknown parameter 0x04"); } /// The first message parameter key on an encoded SUBSCRIBE, or `None` when it carries no @@ -1244,10 +1243,10 @@ mod tests { assert_eq!(decoded.properties.group_order, Some(GroupOrder::Descending)); } - /// We stopped sending the parameter, but a peer still sending it shouldn't lose its - /// session over a hint we ignore anyway. + /// GROUP_ORDER left SUBSCRIBE_OK after draft-15. Draft-18 closes the session when a + /// known parameter shows up on a message that does not define it. #[test] - fn test_subscribe_ok_v18_accepts_group_order_parameter() { + fn test_subscribe_ok_v18_rejects_group_order_parameter() { #[rustfmt::skip] let bytes = vec![ 42, // track alias @@ -1256,9 +1255,7 @@ mod tests { 0x02, // descending ]; - let decoded: SubscribeOk = decode_message(&bytes, Version::Draft18).unwrap(); - assert_eq!(decoded.track_alias, 42); - assert_eq!(decoded.properties.group_order, Some(GroupOrder::Descending)); + assert!(decode_message::(&bytes, Version::Draft18).is_err()); } /// Draft-18 removes the `required_request_id_delta` field (#1615), so the @@ -1431,13 +1428,21 @@ mod tests { } } + /// Draft-15 ignores a parameter it does not know. From draft-16 on, a parameter from + /// a later draft is unknown, which closes the session. + #[test] + fn subscribe_ignores_unrecognized_parameters_in_draft15() { + let body = subscribe_body(&[0x01, 0x32, 0x00]); + decode_message::(&body, Version::Draft15).expect("draft-15 ignores NEW_GROUP_REQUEST"); + } + /// A parameter from a later draft is still an unknown parameter, which the draft makes /// a protocol violation. #[test] fn subscribe_refuses_parameters_before_their_draft() { for (version, params) in [ - // NEW_GROUP_REQUEST arrived in draft-16. - (Version::Draft15, &[0x01, 0x32, 0x00][..]), + // SUBGROUP_DELIVERY_TIMEOUT arrived in draft-18, and 0x06 is not a draft-16 id. + (Version::Draft16, &[0x01, 0x06, 0x00][..]), // The Range Filters arrived in draft-19. (Version::Draft18, &[0x01, 0x25, 0x00][..]), // INCLUDE_PROPERTIES arrived in draft-20. @@ -1468,6 +1473,26 @@ mod tests { let decoded: SubscribeUpdate = decode_message(&body, Version::Draft20).unwrap(); assert_eq!(decoded.request_id, RequestId(2)); } + + /// SUBGROUP_DELIVERY_TIMEOUT (0x06) is not a draft-16 parameter. Draft-18 defines it + /// for SUBSCRIBE, and the value is dropped. + #[test] + fn subgroup_delivery_timeout_follows_its_draft() { + let head: &[u8] = &[ + 0x01, 0x01, 0x04, b'l', b'i', b'v', b'e', 0x05, b'v', b'i', b'd', b'e', b'o', + ]; + let body = [head, &[0x01, 0x06, 0x00][..]].concat(); + assert!(decode_message::(&body, Version::Draft16).is_err()); + decode_message::(&body, Version::Draft18).expect("draft-18 accepts SUBGROUP_DELIVERY_TIMEOUT"); + + // GROUP_ORDER (0x22) is known in draft-16 but not defined for REQUEST_UPDATE. + // Request ID, Subscription Request ID, one parameter, absolute key, varint value. + let update16: &[u8] = &[0x02, 0x0A, 0x01, 0x22, 0x02]; + decode_message::(update16, Version::Draft16).expect("draft-16 ignores GROUP_ORDER"); + // Draft-18 has no Subscription Request ID. The value is a uint8. + let update18: &[u8] = &[0x02, 0x01, 0x22, 0x02]; + assert!(decode_message::(update18, Version::Draft18).is_err()); + } } #[cfg(test)] diff --git a/rs/moq-net/src/ietf/subscribe_namespace.rs b/rs/moq-net/src/ietf/subscribe_namespace.rs index f09eb8f9a55..8b91400e6ae 100644 --- a/rs/moq-net/src/ietf/subscribe_namespace.rs +++ b/rs/moq-net/src/ietf/subscribe_namespace.rs @@ -138,8 +138,13 @@ impl Message for SubscribeNamespaceLegacy<'_> { }; // The token is ignored: the session's grant is what authorizes the request. + // FORWARD is legal here in draft-15 through draft-17. The value is checked (only + // 0 or 1) and then dropped: a namespace subscription has no objects to forward. + // Draft-14 has no such parameter, so an unlisted id is ignored. Draft-18 moved + // FORWARD onto SUBSCRIBE_TRACKS and closes if it shows up on the new message. decode_params!(r, version, 0x03 => _authorization_token: Vec, + 0x10 => _forward: Option where matches!(version, Version::Draft15 | Version::Draft16 | Version::Draft17), HIDDEN_PARAM => hidden: Option, ); @@ -439,6 +444,45 @@ mod tests { ); } + /// FORWARD (0x10) is legal on SUBSCRIBE_NAMESPACE through draft-17. A value other + /// than 0 or 1 still closes the session. Draft-18 dropped it from this message. + #[test] + fn forward_follows_the_draft() { + fn with_forward(version: Version, value: u64) -> Vec { + let mut buf = Vec::new(); + let w = &mut Encoder::new(&mut buf, version.into()); + RequestId(1).encode(w, version).unwrap(); + if version == Version::Draft17 { + w.varint(0).unwrap(); + } + encode_namespace(w, &Path::default()).unwrap(); + if matches!(version, Version::Draft16 | Version::Draft17) { + w.varint(1).unwrap(); + } + // Count, absolute key, then the raw varint. encode_params! needs a Result. + w.varint(1).unwrap(); + w.varint(0x10).unwrap(); + w.varint(value).unwrap(); + buf + } + + for version in [Version::Draft15, Version::Draft16, Version::Draft17] { + let mut buf = bytes::Bytes::from(with_forward(version, 0)); + crate::coding::decode_buf(&mut buf, version, SubscribeNamespaceLegacy::decode_msg) + .unwrap_or_else(|err| panic!("{version} FORWARD=0: {err}")); + assert!(buf.is_empty(), "{version}"); + + let mut buf = bytes::Bytes::from(with_forward(version, 2)); + assert!( + crate::coding::decode_buf(&mut buf, version, SubscribeNamespaceLegacy::decode_msg).is_err(), + "{version} FORWARD=2" + ); + } + + let mut buf = bytes::Bytes::from(with_forward(Version::Draft18, 0)); + assert!(crate::coding::decode_buf(&mut buf, Version::Draft18, SubscribeNamespace::decode_msg).is_err()); + } + #[test] fn message_ids() { // 0x11 through draft-17 (legacy), renumbered to 0x50 in draft-18 (#1542). From 3718bef74c90a8dff9a301c89aaaffdab63afcec Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 7 Oct 2026 19:28:51 -0700 Subject: [PATCH 3/6] fix(js): decode a negotiated PUBLISH_NAMESPACE against its own parameter list Co-Authored-By: Claude Opus 5.5 --- js/net/src/ietf/cluster.test.ts | 22 ++++++++++++++++++++++ js/net/src/ietf/cluster.ts | 11 ++++++++--- js/net/src/ietf/publish_namespace.ts | 2 +- js/net/src/ietf/subscribe_namespace.ts | 2 +- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/js/net/src/ietf/cluster.test.ts b/js/net/src/ietf/cluster.test.ts index 83a0cc33310..a4c2626c465 100644 --- a/js/net/src/ietf/cluster.test.ts +++ b/js/net/src/ietf/cluster.test.ts @@ -4,6 +4,8 @@ import { type Hop, HopSchema, UNKNOWN_HOP } from "../hop.ts"; import * as Path from "../path.ts"; import { Reader, Writer } from "../stream.ts"; import * as Cluster from "./cluster.ts"; +import * as Message from "./message.ts"; +import * as Namespace from "./namespace.ts"; import { Parameters, SetupOption, SetupOptions } from "./parameters.ts"; import { PublishNamespace, PublishNamespaceUpdate } from "./publish_namespace.ts"; import { SubscribeNamespaceEntry } from "./subscribe_namespace.ts"; @@ -229,6 +231,26 @@ test("Cluster: PUBLISH_NAMESPACE carries the parameters only once negotiated", a await expect(PublishNamespace.decode(reader(await encode(bare)), VERSION, true)).rejects.toThrow(ProtocolViolation); }); +test("Cluster: a negotiated PUBLISH_NAMESPACE may carry AUTHORIZATION_TOKEN", async () => { + // The advertisement shares its decode with NAMESPACE, whose list has no token. A + // PUBLISH_NAMESPACE's own list does, so the token must not close the session. + const advert = { hops: hops(7n, 9n), cost: 5n }; + const withToken = { + async encode(w: Writer, version: IetfVersion) { + await Message.encode(w, async (wr) => { + await wr.u62(1n); + await Namespace.encode(wr, Path.from("alice.hang")); + const params = Cluster.intoParams(advert); + params.bytes.set(0x03n, new Uint8Array([1, 2, 3])); // AUTHORIZATION_TOKEN + await params.encode(wr, version); + }); + }, + }; + + const decoded = await PublishNamespace.decode(reader(await encode(withToken)), VERSION, true); + expect(decoded.cluster).toEqual(advert); +}); + test("Cluster: every malformed PUBLISH_NAMESPACE update is a protocol violation", async () => { const valid = await encode(new PublishNamespaceUpdate({ requestId: 1n, update: { cost: 2n } })); const trailing = new Uint8Array(valid.byteLength + 1); diff --git a/js/net/src/ietf/cluster.ts b/js/net/src/ietf/cluster.ts index da7c2024ade..a8c3a35a036 100644 --- a/js/net/src/ietf/cluster.ts +++ b/js/net/src/ietf/cluster.ts @@ -204,7 +204,8 @@ function encodeHops(hops: Hop[]): Uint8Array { } /** - * Read the parameters a negotiated session puts on every advertisement. + * Read the parameters a negotiated session puts on every advertisement, checked against + * the list of the message that carries them (PUBLISH_NAMESPACE also allows a token). * * The parameter block is mandatory there, so a message that ends before it (the base form) * or one whose block does not parse is the peer's violation, same as a block that parses but @@ -212,10 +213,14 @@ function encodeHops(hops: Hop[]): Uint8Array { * * @internal */ -export async function decodeParams(r: Reader, version: IetfVersion): Promise { +export async function decodeParams( + r: Reader, + version: IetfVersion, + message: "namespace" | "publish-namespace", +): Promise { let params: Parameters; try { - params = await Parameters.decode(r, version, "namespace"); + params = await Parameters.decode(r, version, message); } catch (err) { throw new ProtocolViolation(reason(err), { cause: err }); } diff --git a/js/net/src/ietf/publish_namespace.ts b/js/net/src/ietf/publish_namespace.ts index a53a82ab803..ad0da3ec601 100644 --- a/js/net/src/ietf/publish_namespace.ts +++ b/js/net/src/ietf/publish_namespace.ts @@ -62,7 +62,7 @@ export class PublishNamespace { } const trackNamespace = await Namespace.decode(r); if (negotiated) { - const cluster = await Cluster.decodeParams(r, version); + const cluster = await Cluster.decodeParams(r, version, "publish-namespace"); return new PublishNamespace({ requestId, trackNamespace, cluster }); } diff --git a/js/net/src/ietf/subscribe_namespace.ts b/js/net/src/ietf/subscribe_namespace.ts index d087690a1c7..8b997dbe3b9 100644 --- a/js/net/src/ietf/subscribe_namespace.ts +++ b/js/net/src/ietf/subscribe_namespace.ts @@ -296,7 +296,7 @@ export class SubscribeNamespaceEntry { const suffix = await Namespace.decode(r); if (!negotiated) return new SubscribeNamespaceEntry({ suffix }); - return new SubscribeNamespaceEntry({ suffix, cluster: await Cluster.decodeParams(r, version) }); + return new SubscribeNamespaceEntry({ suffix, cluster: await Cluster.decodeParams(r, version, "namespace") }); } } From 234944f7e577a8993994e82b2d9f25ac6111a8a9 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 7 Oct 2026 20:06:50 -0700 Subject: [PATCH 4/6] chore: finish the params-per-draft and first-object-zero quests Co-Authored-By: Claude Opus 5.5 --- doc/concept/standard.md | 8 ++-- quest/m0/README.md | 2 - quest/m0/ietf-first-object-zero.md | 32 ---------------- quest/m0/ietf-params-per-draft.md | 60 ------------------------------ 4 files changed, 5 insertions(+), 97 deletions(-) delete mode 100644 quest/m0/ietf-first-object-zero.md delete mode 100644 quest/m0/ietf-params-per-draft.md diff --git a/doc/concept/standard.md b/doc/concept/standard.md index c8c2e59e4cd..7d1d98c69c1 100644 --- a/doc/concept/standard.md +++ b/doc/concept/standard.md @@ -108,9 +108,11 @@ leaving the session open: a `SUBSCRIBE` with `FORWARD=0`, a `SUBSCRIBE` or `FETCH` carrying `FILL_TIMEOUT` (Timed-Out gaps are not written), `TRACK_STATUS`, `SUBSCRIBE_TRACKS` (draft-18 and later), and the `FETCH` forms above. `NEW_GROUP_REQUEST` is ignored, as -the draft allows a publisher without dynamic groups to do. A parameter the -negotiated draft does not define still closes the session with -`PROTOCOL_VIOLATION`, as the draft requires. +the draft allows a publisher without dynamic groups to do. Message parameters +follow the negotiated draft's lists: draft-14 and draft-15 ignore an unknown or +misplaced parameter, draft-16 ignores one defined only for another message but +closes the session with `PROTOCOL_VIOLATION` on an unknown one, and draft-17 +and later close it on both. Several project drafts extend the IETF wire without breaking it, since `SETUP` ignores unknown parameters: [cluster](/draft/moq-cluster) routing hop lists, diff --git a/quest/m0/README.md b/quest/m0/README.md index eaba0ebb218..b4ebcdb26d0 100644 --- a/quest/m0/README.md +++ b/quest/m0/README.md @@ -51,13 +51,11 @@ a published `@moq/watch` break. - [Held group wakes](/quest/m0/held-group-wakes.md) - a group held across a route switch is woken when its successor's first timestamp or abort makes it stale, not at the next unrelated append - [Draft-22 LOCATION_FILTER](/quest/m0/ietf-location-filter-22.md) - moqt-22 LOCATION_FILTER carries its type instead of a Length in Rust and JS, so a draft-22 peer reads our Next Object correctly -- [moq-transport parameters per draft](/quest/m0/ietf-params-per-draft.md) - every control message accepts exactly the parameters its draft allows, so moqx's draft-16 SUBSCRIBE_NAMESPACE with FORWARD stops failing - [NAMESPACE on the stream](/quest/m0/ietf-namespace-stream.md) - every draft-16+ SUBSCRIBE_NAMESPACE stream carries NAMESPACE for each match, whatever the peer's SETUP options - [Dialed split horizon](/quest/m0/dial-split-horizon.md) - a session moq-net dials gets a per-connection hop, so routes never echo back to the peer they came from - [No empty d14 prefix](/quest/m0/ietf-d14-root-prefix.md) - draft-14 never sends SUBSCRIBE_NAMESPACE with an empty prefix, and the docs say to scope a d14 link to moxygen - [End of Track Location](/quest/m0/ietf-end-of-track-location.md) - a relay forwards END_OF_TRACK at its upstream's Location, on the last group's stream, instead of re-sending it at the next group's object 0 - [End of Group status](/quest/m0/ietf-end-of-group-status.md) - an End of Group status on a stream whose header already marks the group's end is accepted, so imquic's last object per group arrives -- [Subgroup at object 0](/quest/m0/ietf-first-object-zero.md) - a draft-18 subgroup with FIRST_OBJECT clear that starts at object 0 is read whole - [Request caps](/quest/m0/request-caps.md) - lite message sizes, IETF request IDs, and per-session announces and subscriptions are bounded - [Prefix route fronts](/quest/m0/prefix-route-fronts.md) - a prefix route cannot be made to mint one front per requested path - [qmux credit](/quest/m0/qmux-credit.md) - qmux returns connection credit for dropped and stopped streams and delivers its close frame, on both lines diff --git a/quest/m0/ietf-first-object-zero.md b/quest/m0/ietf-first-object-zero.md deleted file mode 100644 index 701c72f4980..00000000000 --- a/quest/m0/ietf-first-object-zero.md +++ /dev/null @@ -1,32 +0,0 @@ -# [XS] A subgroup starting at object 0 is whole - -## Goal - -A draft-18+ subgroup stream with FIRST_OBJECT clear whose first Object ID -is 0 is read as a whole group, in `rs/moq-net`, instead of being dropped as -"a group with no head". A clear bit with any other first ID is still dropped -as it is today. - -## Plan - -Triaged from Fastly's moq-relay-interop report (2026-09-23 run, item 7) on -2026-10-07. d18 §2.2 says the original publisher MUST set FIRST_OBJECT when -it opens a subgroup, and a relay MUST keep it set, so the probe that left it -clear was the one out of spec. The first Object ID is absolute whatever -the bit says (§11.4.2), and object IDs in our model start at 0, so ID 0 is -the head either way. - -Decided 2026-10-07: accept it anyway, to be lenient toward publishers that -are out of spec. Rejected: keeping the drop and documenting it. - -Where it lives: `rs/moq-net/src/ietf/subscriber.rs` (around line 2611) -drops the stream before reading any object. `next_object_id` already -refuses a first ID other than the group's start (0 for a whole group), so -check whether letting a clear-bit stream through to it is enough before -adding a second peek. Check whether `js/net` drops these streams at all; it -has no matching check today. - -Test: a d18 stream with FIRST_OBJECT clear and first ID 0 delivers its -group; one with first ID 3 is still dropped. - -Public API: none. Wire: none. diff --git a/quest/m0/ietf-params-per-draft.md b/quest/m0/ietf-params-per-draft.md deleted file mode 100644 index fd81987dca6..00000000000 --- a/quest/m0/ietf-params-per-draft.md +++ /dev/null @@ -1,60 +0,0 @@ -# [M] moq-transport parameters follow each draft's lists - -## Goal - -Every control message accepts exactly the parameters its draft allows, in -`rs/moq-net` and `js/net`, for each supported draft (14 through 22). A -parameter the draft defines for that message is decoded or skipped. Drafts -14 and 15 ignore unknown and misplaced parameters alike; draft-16 closes the -session with PROTOCOL_VIOLATION on an unknown key but ignores a misplaced -one; draft-17 and later close it on both. The case seen in the wild: -moqx's draft-16 SUBSCRIBE_NAMESPACE carries FORWARD (0x10), which we refuse, -and moqx redials in a loop. - -## Plan - -Triaged from Fastly's moq-relay-interop report (run of 2026-09-23, build -7ee2b02) on 2026-10-07. Facts from the draft text: - -- Unknown message parameter: d14 and d15 §9.2 say "Receivers ignore - unrecognized parameters"; d16 §9.2, d17 §9.3, d18 §10.2 and d22 §9.20 - close with PROTOCOL_VIOLATION. -- A known parameter in a message it is not defined for: d14, d15 and d16 - (§9.2.2) say "it MUST be ignored"; d17 §9.3.1, d18 §10.2.1 and d22 - §9.20.1 close the session. -- d16 allows FORWARD on SUBSCRIBE, REQUEST_UPDATE, PUBLISH, PUBLISH_OK and - SUBSCRIBE_NAMESPACE. d18 drops it from SUBSCRIBE_NAMESPACE (moved to - SUBSCRIBE_TRACKS). - -Decided 2026-10-07: audit every message against every draft rather than -patch FORWARD alone, since the report's EXPIRES case (fixed in #4195) and -this one are the same class. - -Where it lives: the `decode_params!` macro (`rs/moq-net/src/ietf/parameters.rs`, -around line 473) returns `InvalidValue` for any key outside a message's list. -Its call sites are in `fetch.rs`, `publish_namespace.rs`, `publish.rs`, -`subscribe_namespace.rs`, `request_stream.rs`, `request.rs` and -`subscribe.rs`. `Parameters::skip` ignores unknown keys, but only d14 -SUBSCRIBE, FETCH and PUBLISH use it; the legacy d14 to d17 decodes of -SUBSCRIBE_NAMESPACE, PUBLISH_NAMESPACE and the `request*.rs` messages go -through `decode_params!`, so they refuse unknown keys on d14 and d15 today -(`test_param_unknown_rejected` asserts that). Those are gaps. - -Accepting FORWARD=0 on a d16 SUBSCRIBE_NAMESPACE can be accept-and-ignore: -it only sets FORWARD on the PUBLISH messages it triggers, and we send none -for that subscription (Subscribe Options 0x01). - -Coordinate with [moq-transport request codes](/quest/m2/ietf-request-codes.md), -which accepts the delivery-timeout parameters on REQUEST_UPDATE; whichever -lands second drops the overlap. - -Tests: one codec test per gap the audit finds, plus one per rule above -(unknown and misplaced, on each side of the d16 and d17 boundaries). Mirror -in `js/net/src/ietf` in the same PR. `doc/concept/standard.md` says an -undefined parameter always closes the session; correct it. - -Public API: none. Wire: none new; decoding moves closer to the drafts. - -## Related - -- [Malformed moq-transport input](/quest/m2/ietf-malformed-close.md) - owns the other session-closing cases From 10accc32eb6afee36fed64bc7bf28b829fdf7d2e Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 7 Oct 2026 21:24:29 -0700 Subject: [PATCH 5/6] fix(net): reject TRACK_NAMESPACE_PREFIX on a subscription update A REQUEST_UPDATE on a SUBSCRIBE stream carrying TRACK_NAMESPACE_PREFIX was consumed and acked. The parameter only updates a SUBSCRIBE_NAMESPACE or SUBSCRIBE_TRACKS, so it now closes the session like any misplaced parameter. Also drop post-decode checks the per-draft gates made unreachable, and the unused JS publish-ok and fetch-ok allow-lists. Co-Authored-By: Claude Opus 5.5 --- js/net/src/ietf/ietf.test.ts | 10 +++++ js/net/src/ietf/parameters.ts | 44 +-------------------- rs/moq-net/src/ietf/fetch.rs | 6 --- rs/moq-net/src/ietf/parameters.rs | 20 ---------- rs/moq-net/src/ietf/request_stream.rs | 23 +++++++++-- rs/moq-net/src/ietf/subscribe.rs | 55 +++++---------------------- 6 files changed, 42 insertions(+), 116 deletions(-) diff --git a/js/net/src/ietf/ietf.test.ts b/js/net/src/ietf/ietf.test.ts index 25b082f39e2..85abfe330ab 100644 --- a/js/net/src/ietf/ietf.test.ts +++ b/js/net/src/ietf/ietf.test.ts @@ -1608,6 +1608,16 @@ test("Parameters: a known parameter on the wrong message", async () => { ).rejects.toThrow(ProtocolViolation); }); +// TRACK_NAMESPACE_PREFIX updates a SUBSCRIBE_NAMESPACE or SUBSCRIBE_TRACKS only, so a +// subscription's REQUEST_UPDATE carrying it closes the session instead of being acked. +test("Parameters: TRACK_NAMESPACE_PREFIX is not a subscription update parameter", async () => { + // One parameter: TRACK_NAMESPACE_PREFIX (0x34), a one-field namespace "a". + const block = new Uint8Array([0x01, 0x34, 0x01, 0x01, 0x61]); + await expect( + Parameters.decode(new Reader(undefined, block, Version.DRAFT_18), Version.DRAFT_18, "request-update"), + ).rejects.toThrow(ProtocolViolation); +}); + test("Subscribe: SUBGROUP_DELIVERY_TIMEOUT follows its draft", async () => { const body = framed([...TRACK_HEAD, 0x01, 0x06, 0x00]); await expect(decodeVersioned(body, Subscribe.Subscribe.decode, Version.DRAFT_16)).rejects.toThrow( diff --git a/js/net/src/ietf/parameters.ts b/js/net/src/ietf/parameters.ts index a756b2dd6e0..51cc6de1557 100644 --- a/js/net/src/ietf/parameters.ts +++ b/js/net/src/ietf/parameters.ts @@ -1,7 +1,6 @@ import { ProtocolViolation } from "../error.ts"; import type { Reader, Writer } from "../stream.ts"; import * as Varint from "../varint.ts"; -import * as Namespace from "./namespace.ts"; import { type IetfVersion, Version } from "./version.ts"; /// Setup Option key constants (separate namespace from Message Parameters). @@ -224,8 +223,6 @@ const MSG_PARAM_SUBSCRIPTION_FILTER = 0x21n; const MSG_PARAM_FILL_PARAMETERS = 0x23n; /// HOP_PATH, from the MoQ Cluster extension. See `cluster.ts`. const MSG_PARAM_HOP_PATH = 0x40b57n; -/// TRACK_NAMESPACE_PREFIX (0x34). A Track Namespace tuple, not a varint. -const MSG_PARAM_TRACK_NAMESPACE_PREFIX = 0x34n; /// ACTIVE_COUNT, from the MoQ Active Count extension. const MSG_PARAM_ACTIVE_COUNT = 0x40b66n; @@ -239,10 +236,8 @@ type ControlMessage = | "subscribe-update" | "subscribe-namespace" | "publish" - | "publish-ok" | "publish-namespace" | "fetch" - | "fetch-ok" | "request-ok" | "request-update" | "namespace"; @@ -256,8 +251,6 @@ function allows(message: ControlMessage, version: IetfVersion, id: bigint): bool const d15 = version === Version.DRAFT_15; const d16 = version === Version.DRAFT_16; const d17 = version === Version.DRAFT_17; - const d18 = version === Version.DRAFT_18; - const d19 = version === Version.DRAFT_19; const from16 = version >= Version.DRAFT_16; const from17 = version >= Version.DRAFT_17; const from18 = version >= Version.DRAFT_18; @@ -277,7 +270,6 @@ function allows(message: ControlMessage, version: IetfVersion, id: bigint): bool const fill = id === MSG_PARAM_FILL_PARAMETERS && draft20(version); const include = id === MSG_PARAM_INCLUDE_PROPERTIES && draft20(version); const newGroup = id === MSG_PARAM_NEW_GROUP_REQUEST && from16; - const prefix = id === MSG_PARAM_TRACK_NAMESPACE_PREFIX && from18; switch (message) { case "subscribe": @@ -309,8 +301,7 @@ function allows(message: ControlMessage, version: IetfVersion, id: bigint): bool fill || range || trackRange || - newGroup || - prefix + newGroup ); case "subscribe-namespace": return auth || (forward && legacyForward) || id === MSG_PARAM_HIDDEN; @@ -326,17 +317,6 @@ function allows(message: ControlMessage, version: IetfVersion, id: bigint): bool (filter && draft20(version)) || (order && (d15 || draft20(version))) ); - case "publish-ok": - return ( - (objectTimeout && !draft20(version)) || - (id === MSG_PARAM_SUBGROUP_DELIVERY_TIMEOUT && (d18 || d19)) || - expires || - (forward && !draft20(version)) || - (priority && !draft20(version)) || - (filter && !draft20(version)) || - (order && (d15 || d16 || d17 || d18)) || - (id === MSG_PARAM_NEW_GROUP_REQUEST && (d16 || d17 || d18 || d19)) - ); case "publish-namespace": return auth || id === MSG_PARAM_HOP_PATH || id === MSG_PARAM_ROUTE_COST; case "fetch": @@ -349,8 +329,6 @@ function allows(message: ControlMessage, version: IetfVersion, id: bigint): bool range || include ); - case "fetch-ok": - return (id === MSG_PARAM_MAX_CACHE_DURATION && d15) || (order && d15); case "request-ok": return expires || largest || id === MSG_PARAM_ACTIVE_COUNT; case "namespace": @@ -726,19 +704,7 @@ export class Parameters { static async decode( r: Reader, version: IetfVersion, - message?: - | "subscribe" - | "subscribe-ok" - | "subscribe-update" - | "subscribe-namespace" - | "publish" - | "publish-ok" - | "publish-namespace" - | "fetch" - | "fetch-ok" - | "request-ok" - | "request-update" - | "namespace", + message?: ControlMessage, ): Promise { const count = await r.u53(); const params = new Parameters(); @@ -769,12 +735,6 @@ export class Parameters { continue; } - // Even id, but the value is a Track Namespace tuple rather than a varint. - if (id === MSG_PARAM_TRACK_NAMESPACE_PREFIX && version >= Version.DRAFT_17) { - await Namespace.decode(r); - continue; - } - if (version === Version.DRAFT_14 || version === Version.DRAFT_15 || version === Version.DRAFT_16) { if (id % 2n === 0n) { if (params.vars.has(id)) { diff --git a/rs/moq-net/src/ietf/fetch.rs b/rs/moq-net/src/ietf/fetch.rs index 6622610eb88..86d29894888 100644 --- a/rs/moq-net/src/ietf/fetch.rs +++ b/rs/moq-net/src/ietf/fetch.rs @@ -221,12 +221,6 @@ impl Message for Fetch<'_> { .iter() .any(|filter| !filter.is_empty()); - // Range Filters arrived in draft-19. An earlier draft-16+ peer sending one - // is an unknown parameter. Draft-15 ignores an unrecognized parameter. - if range_filters && !has_range_filters(version) { - return Err(DecodeError::InvalidValue); - } - ( fetch_type, subscriber_priority, diff --git a/rs/moq-net/src/ietf/parameters.rs b/rs/moq-net/src/ietf/parameters.rs index 79fc75f1d3f..b55a16a46de 100644 --- a/rs/moq-net/src/ietf/parameters.rs +++ b/rs/moq-net/src/ietf/parameters.rs @@ -413,26 +413,6 @@ impl Param for Opaque { } } -/// TRACK_NAMESPACE_PREFIX (0x34). The value is a Track Namespace tuple, not a varint, -/// so it has to be consumed or the parameters after it land on the wrong bytes. The -/// prefix itself is not applied: this message cannot say which request it updates. -#[derive(Clone, Debug, PartialEq, Eq)] -pub(crate) struct TrackNamespace { - pub(crate) path: crate::Path<'static>, -} - -impl Param for TrackNamespace { - fn param_encode(&self, w: &mut Encoder<'_>, _: Version) -> Result<(), EncodeError> { - super::namespace::encode_namespace(w, &self.path) - } - - fn param_decode(r: &mut Decoder<'_>, _: Version) -> Result { - Ok(Self { - path: super::namespace::decode_namespace(r)?, - }) - } -} - /// Message parameter ids defined in draft-16. Sorted for `binary_search`. /// /// A known id on a message that does not list it is ignored. An id outside this set diff --git a/rs/moq-net/src/ietf/request_stream.rs b/rs/moq-net/src/ietf/request_stream.rs index e9bf3363251..de820911170 100644 --- a/rs/moq-net/src/ietf/request_stream.rs +++ b/rs/moq-net/src/ietf/request_stream.rs @@ -145,9 +145,6 @@ impl Update { 0x28 => property_filter: Vec where super::subscribe::has_range_filters(version), 0x29 => track_filter: Vec where super::subscribe::has_range_filters(version), 0x32 => new_group: Option where !matches!(version, Version::Draft14 | Version::Draft15), - // Legal on a SUBSCRIBE_NAMESPACE update from draft-18. The message cannot - // say which request it updates, so the prefix is consumed and not applied. - 0x34 => _prefix: Option where !matches!(version, Version::Draft14 | Version::Draft15 | Version::Draft16 | Version::Draft17), ); if !data.is_empty() { return Err(DecodeError::InvalidValue); @@ -182,3 +179,23 @@ impl Decode for Update { Self::decode_body(&mut data, version).map_err(DecodeError::complete) } } + +#[cfg(test)] +mod tests { + use super::*; + + /// TRACK_NAMESPACE_PREFIX (0x34) updates a SUBSCRIBE_NAMESPACE or SUBSCRIBE_TRACKS only, + /// so on a subscription's REQUEST_UPDATE it closes the session instead of being acked. + #[test] + fn namespace_prefix_on_subscription_update_closes() { + // Request ID 2, one parameter: TRACK_NAMESPACE_PREFIX, a one-field namespace "a". + let mut buf = bytes::Bytes::from_static(&[0x02, 0x01, 0x34, 0x01, 0x01, b'a']); + assert!(crate::coding::decode_buf(&mut buf, Version::Draft18, Update::decode_body).is_err()); + + // The same update with only a priority is accepted. + let mut buf = bytes::Bytes::from_static(&[0x02, 0x01, 0x20, 0x05]); + let update = crate::coding::decode_buf(&mut buf, Version::Draft18, Update::decode_body).unwrap(); + assert_eq!(update.priority, Some(5)); + assert!(!update.unsupported); + } +} diff --git a/rs/moq-net/src/ietf/subscribe.rs b/rs/moq-net/src/ietf/subscribe.rs index 6df3e47df11..b1184b29888 100644 --- a/rs/moq-net/src/ietf/subscribe.rs +++ b/rs/moq-net/src/ietf/subscribe.rs @@ -104,7 +104,7 @@ impl Message for Subscribe<'_> { 0x26 => object_id_filter: Vec where has_range_filters(version), 0x27 => priority_filter: Vec where has_range_filters(version), 0x28 => object_property_filter: Vec where has_range_filters(version), - 0x32 => new_group_request: Option where has_new_group_request(version), + 0x32 => _new_group_request: Option where has_new_group_request(version), 0x35 => include_properties: Option where Filter::is_draft20(version), ); @@ -117,16 +117,6 @@ impl Message for Subscribe<'_> { .iter() .any(|filter| !filter.is_empty()); - // A parameter that arrived in a later draft is unknown from draft-16 on, which - // closes the session. The gates above are what reject it. Draft-14 and draft-15 - // ignore an unrecognized parameter instead, so it never reaches these checks. - if ((fill.is_some() || include_properties.is_some()) && !Filter::is_draft20(version)) - || (range_filters && !has_range_filters(version)) - || (new_group_request.is_some() && !has_new_group_request(version)) - { - return Err(DecodeError::InvalidValue); - } - // Defaults to 1, so an absent parameter means the subscriber wants them. let properties_wanted = include_properties.unwrap_or(true); @@ -463,14 +453,9 @@ impl Message for SubscribeUpdate { 0x10 => forward: Option, 0x20 => subscriber_priority: Option, 0x21 => _filter: Option, - 0x32 => new_group_request: Option where has_new_group_request(version), + 0x32 => _new_group_request: Option where has_new_group_request(version), ); - // NEW_GROUP_REQUEST arrived in draft-16. - if new_group_request.is_some() && !has_new_group_request(version) { - return Err(DecodeError::InvalidValue); - } - let subscriber_priority = subscriber_priority.unwrap_or(128); let forward = forward.unwrap_or(true); @@ -489,11 +474,8 @@ impl Message for SubscribeUpdate { if matches!(version, Version::Draft17) { let _required_request_id_delta = r.varint()?; } - // Nothing reads an update's Range Filters yet; they are consumed so a legal - // update does not fail the session. TRACK_PROPERTY_FILTER (0x29) and - // TRACK_NAMESPACE_PREFIX (0x34) are legal only on some request types, which - // the message alone can't tell, so a legal update is accepted and the value - // is not applied. + // Nothing reads an update's FILL_PARAMETERS or Range Filters yet; they are + // consumed so a legal update does not fail the session. decode_params!(r, version, 0x02 => _object_delivery_timeout: Option, 0x03 => _authorization_token: Vec, @@ -501,32 +483,15 @@ impl Message for SubscribeUpdate { 0x10 => forward: Option, 0x20 => subscriber_priority: Option, 0x21 => _filter: Option, - 0x23 => fill: Option where Filter::is_draft20(version), - 0x25 => subgroup_filter: Vec where has_range_filters(version), - 0x26 => object_id_filter: Vec where has_range_filters(version), - 0x27 => priority_filter: Vec where has_range_filters(version), - 0x28 => object_property_filter: Vec where has_range_filters(version), - 0x29 => track_property_filter: Vec where has_range_filters(version), + 0x23 => _fill: Option where Filter::is_draft20(version), + 0x25 => _subgroup_filter: Vec where has_range_filters(version), + 0x26 => _object_id_filter: Vec where has_range_filters(version), + 0x27 => _priority_filter: Vec where has_range_filters(version), + 0x28 => _object_property_filter: Vec where has_range_filters(version), + 0x29 => _track_property_filter: Vec where has_range_filters(version), 0x32 => _new_group_request: Option, - 0x34 => _prefix: Option where !matches!(version, Version::Draft14 | Version::Draft15 | Version::Draft16 | Version::Draft17), ); - let range_filters = [ - subgroup_filter, - object_id_filter, - priority_filter, - object_property_filter, - track_property_filter, - ] - .iter() - .any(|filter| !filter.is_empty()); - - // FILL_PARAMETERS and the Range Filters postdate draft-17, so an earlier peer - // sending one is still the protocol violation it was. - if (fill.is_some() && !Filter::is_draft20(version)) || (range_filters && !has_range_filters(version)) { - return Err(DecodeError::InvalidValue); - } - let subscriber_priority = subscriber_priority.unwrap_or(128); let forward = forward.unwrap_or(true); From 698224f7ef2cb1b541a0496cd2a0d07fd70bdd35 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 7 Oct 2026 21:50:18 -0700 Subject: [PATCH 6/6] style(net): format Parameters.decode signature Co-Authored-By: Claude Opus 5.5 --- js/net/src/ietf/parameters.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/js/net/src/ietf/parameters.ts b/js/net/src/ietf/parameters.ts index 51cc6de1557..70473ee7cfd 100644 --- a/js/net/src/ietf/parameters.ts +++ b/js/net/src/ietf/parameters.ts @@ -701,11 +701,7 @@ export class Parameters { * draft-16 on. Draft-14 and draft-15 ignore anything the message does not list. * Omitting `message` keeps the previous decode, which stores every id. */ - static async decode( - r: Reader, - version: IetfVersion, - message?: ControlMessage, - ): Promise { + static async decode(r: Reader, version: IetfVersion, message?: ControlMessage): Promise { const count = await r.u53(); const params = new Parameters();