From 59925048d04af2bb01db8675bc4f7a27400a5c44 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 18:36:45 -0700 Subject: [PATCH 1/2] fix(net): refuse navigation segments in published names Co-Authored-By: GPT-6 --- js/net/MIGRATE.md | 6 ++++++ js/net/src/origin.test.ts | 19 +++++++++++++++++++ js/net/src/origin.ts | 9 +++++++++ rs/moq-net/MIGRATE.md | 7 +++++++ rs/moq-net/src/error.rs | 15 +++++++++++---- rs/moq-net/src/model/origin.rs | 30 +++++++++++++++++++++++++++++- 6 files changed, 81 insertions(+), 5 deletions(-) diff --git a/js/net/MIGRATE.md b/js/net/MIGRATE.md index 85a6485f847..90b10e59516 100644 --- a/js/net/MIGRATE.md +++ b/js/net/MIGRATE.md @@ -4,6 +4,12 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Published names refuse navigation segments + +Broadcast creation and route publication now refuse literal `.` and `..` segments, including segments in the producer's root. +Resolve relative references before publishing, or rename broadcasts that used these segments. +Path normalization, relative references, and subscription paths retain their semantics. + ### Stage a requested track before subscribers see it (#6111) `Track.Request.stage(info)` returns a `Track.Staged` whose `producer` writes while subscribers waiting on the request stay pending; `commit()` publishes it with everything written so far and returns the `Producer`. diff --git a/js/net/src/origin.test.ts b/js/net/src/origin.test.ts index 23ffd232ab3..c389d7b47bd 100644 --- a/js/net/src/origin.test.ts +++ b/js/net/src/origin.test.ts @@ -2684,3 +2684,22 @@ test("public announcements saturate static costs and refuse invalid cost shapes" broadcast.close(); origin.close(); }); + +test("published names refuse navigation segments", () => { + const origin = new Producer(); + try { + for (const name of ["room/./cam", "room/../cam", ".", ".."]) { + const path = Path.from(name); + expect(() => origin.createBroadcast(path)).toThrow(); + expect(() => origin.dynamic(path)).toThrow(); + expect(() => wireOf(origin).receive(path, Route.default)).toThrow(); + } + const scoped = origin.scope(Path.from("room/.."), new Path.Patterns([Path.Pattern.all()])); + expect(() => scoped.createBroadcast(Path.from("cam"))).toThrow(); + for (const path of ["room/.pro/cam", "room/a..b", "room/cam"]) { + origin.createBroadcast(Path.from(path)).close(); + } + } finally { + origin.close(); + } +}); diff --git a/js/net/src/origin.ts b/js/net/src/origin.ts index c42bbc876bb..e25f5a6e59a 100644 --- a/js/net/src/origin.ts +++ b/js/net/src/origin.ts @@ -513,6 +513,13 @@ class VersionedSignal extends Signal { } } +// Navigation belongs to relative references, resolved before publication. +function publishPath(path: Path.Valid): void { + if (Path.parts(path).some((segment) => segment === "." || segment === "..")) { + throw new Error("broadcast path contains a navigation segment"); + } +} + /** Reactive backing state shared by origin producers and consumers. */ class OriginState { // Both tables decouple the application producing into the origin from the @@ -1233,6 +1240,7 @@ export class Producer implements Table { */ createBroadcast(path: Path.Valid): broadcast.Producer { path = this.#scope.path(path); + publishPath(path); const created = this.#state.created; if (!created) throw new Error("origin is closed"); @@ -1344,6 +1352,7 @@ export class Producer implements Table { #insertRoute(prefix: Path.Valid, route: Route, originated: boolean, publishes: boolean): Dynamic { prefix = this.#scope.prefix(prefix); + publishPath(prefix); const server = new ServeState(this.#scope.root, prefix, originated); server.onChange = (path) => this.#state.refresh(path); const entry: RouteEntry = { diff --git a/rs/moq-net/MIGRATE.md b/rs/moq-net/MIGRATE.md index e16d361e179..bac9b14ee62 100644 --- a/rs/moq-net/MIGRATE.md +++ b/rs/moq-net/MIGRATE.md @@ -4,6 +4,13 @@ How to update your code for each breaking change, newest first. ## Unreleased +### Published names refuse navigation segments + +Broadcast creation and route publication now refuse literal `.` and `..` segments, including segments in the producer's root. +Resolve relative references before publishing, or rename broadcasts that used these segments. +Rust reports `Error::NavigationSegment`; the existing protocol error codes carry the refusal to a peer. +Path normalization, relative references, and subscription paths retain their semantics. + ### IETF whole-group FETCH answers name the requested group ([#6199](https://github.com/moq-dev/moq/issues/6199)) On moq-transport drafts 14 through 19, a whole-group `FETCH_OK` now names `{g, 0}` instead of `{g+1, 0}`. diff --git a/rs/moq-net/src/error.rs b/rs/moq-net/src/error.rs index 0f4f1e052dc..cf300d9e851 100644 --- a/rs/moq-net/src/error.rs +++ b/rs/moq-net/src/error.rs @@ -365,6 +365,10 @@ pub enum Error { #[error("invalid path: {0}")] InvalidPath(#[from] crate::InvalidPattern), + /// A published broadcast or route contains a literal `.` or `..` segment. + #[error("broadcast path contains a navigation segment")] + NavigationSegment, + /// A duplicate ID was used // The broadcast/track is a duplicate #[error("duplicate")] @@ -638,7 +642,8 @@ impl From<&Error> for SessionError { | Error::Encode(_) | Error::WrongSize | Error::BoundsExceeded(_) - | Error::InvalidPath(_) => Self::ProtocolViolation, + | Error::InvalidPath(_) + | Error::NavigationSegment => Self::ProtocolViolation, Error::App(app) => Self::App(*app), // A code we did not recognize, so we cannot say which space it came from. // Forwarding it into this one risks landing on a value that IS registered here @@ -700,9 +705,11 @@ impl From<&Error> for StreamError { Error::Timeout => Self::DeliveryTimeout, Error::GoingAway => Self::GoingAway, // Our own parse failure is, from the peer's side, a malformed track. - Error::Decode(_) | Error::BoundsExceeded(_) | Error::InvalidPath(_) | Error::MalformedTrack => { - Self::MalformedTrack - } + Error::Decode(_) + | Error::BoundsExceeded(_) + | Error::InvalidPath(_) + | Error::NavigationSegment + | Error::MalformedTrack => Self::MalformedTrack, Error::App(app) => Self::App(*app), // See the SessionError impl: an unregistered code carries no registry, so // re-sending the number could mistranslate it. diff --git a/rs/moq-net/src/model/origin.rs b/rs/moq-net/src/model/origin.rs index d59a83a9456..01d86951b3e 100644 --- a/rs/moq-net/src/model/origin.rs +++ b/rs/moq-net/src/model/origin.rs @@ -1196,6 +1196,15 @@ impl RouteEntry { } } +// Published names are literal coordinates. Navigation belongs to Relative, +// resolved before publication, so a name remains stable when carried by a URL. +fn publish_path(path: &Path) -> Result<(), Error> { + if path.parts().any(|segment| matches!(segment, "." | "..")) { + return Err(Error::NavigationSegment); + } + Ok(()) +} + /// The paths a prefix can cover, using an exact pattern at the path depth limit. fn prefix_claim(prefix: &Path) -> Result { if prefix.parts().count() == Path::MAX_PARTS { @@ -1958,7 +1967,8 @@ impl Producer { /// [`mount`](Self::mount), /// [`Error::BoundsExceeded`] if the full rooted path exceeds /// [`Path::MAX_PARTS`], [`Error::InvalidPath`] if it holds a segment no - /// pattern can spell (`*` or `**`), or [`Error::Closed`] once the origin's + /// pattern can spell (`*` or `**`), [`Error::NavigationSegment`] for a literal `.` or `..`, + /// or [`Error::Closed`] once the origin's /// [`Driver`] has been dropped. pub fn create_broadcast(&self, path: impl AsPath) -> Result { let full = self.root.join(path.as_path()).to_owned(); @@ -1969,6 +1979,7 @@ impl Producer { /// A new broadcast at `full` with its announcer withheld, so it cannot announce /// until the announcer is handed back. fn create_withheld(&self, full: PathOwned) -> Result<(broadcast::Producer, Announcer), Error> { + publish_path(&full)?; if !self.scope.permits(&full) || !self.scope.publishes(&full) { return Err(Error::Unauthorized); } @@ -2329,6 +2340,7 @@ impl Announcing { /// The requested prefix as-is, refused when its subtree does not overlap the scope. fn new(producer: &Producer, prefix: impl AsPath) -> Result { let requested = producer.root.join(prefix.as_path()).to_owned(); + publish_path(&requested)?; if requested.parts().count() > Path::MAX_PARTS { return Err(BoundsExceeded.into()); } @@ -12739,6 +12751,22 @@ mod tests { let _pending = consumer.request_broadcast("room/a", None); } + #[moq_clock::test] + async fn published_names_refuse_navigation_segments() { + let producer = origin(1).produce(); + for path in ["room/./cam", "room/../cam", ".", ".."] { + assert!(producer.create_broadcast(path).is_err(), "created {path}"); + assert!(producer.announce(path, Route::default()).is_err(), "announced {path}"); + } + let scoped = producer + .scope("room/..", &Patterns::from_iter([Pattern::all()])) + .unwrap(); + assert!(scoped.create_broadcast("cam").is_err()); + for path in ["room/.pro/cam", "room/a..b", "room/cam"] { + producer.create_broadcast(path).unwrap(); + } + } + #[moq_clock::test] async fn create_broadcast_refuses_a_path_no_pattern_can_spell() { let producer = origin(1).produce(); From 1441aea8c35973a67ac7a3c2d9762fcd8224585f Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Thu, 22 Oct 2026 18:48:13 -0700 Subject: [PATCH 2/2] test(net): preserve reserved namespace request coverage Co-Authored-By: GPT-6 --- js/net/src/ietf/publisher.test.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/js/net/src/ietf/publisher.test.ts b/js/net/src/ietf/publisher.test.ts index f4c31751de8..0f747ecdd11 100644 --- a/js/net/src/ietf/publisher.test.ts +++ b/js/net/src/ietf/publisher.test.ts @@ -579,8 +579,13 @@ test("reserved namespace requests get DOES_NOT_EXIST while other dot namespaces for (const path of [".", "./child", ".session", ".session/extension", ".application", ".sessionish"]) { const pair = createMockTransportPair(ALPNS[version]); const { pub, origin } = publisher(pair.server, { session: new NativeSession(pair.server, version, true) }); - const broadcast = publish(origin, Path.from(path)); - const track = broadcast.createTrack("video", { timescale: Timescale.MILLI }); + // Navigation segments cannot be published. A covering application + // route still proves these reserved requests are refused before lookup. + const navigation = path.split("/")[0] === "."; + const claim = navigation ? origin.dynamic(Path.empty()) : undefined; + const requested = claim?.requested().next(); + const broadcast = navigation ? undefined : publish(origin, Path.from(path)); + const track = broadcast?.createTrack("video", { timescale: Timescale.MILLI }); const request = requestStream(version); try { await pub.runTrackStatusRequest(trackStatus(path), request.stream); @@ -594,9 +599,11 @@ test("reserved namespace requests get DOES_NOT_EXIST while other dot namespaces } } finally { request.cancel(); - track.close(); - broadcast.close(); + track?.close(); + broadcast?.close(); + claim?.close(); origin.close(); + if (requested) expect((await requested).done).toBe(true); } } }