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
6 changes: 6 additions & 0 deletions js/net/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

### A listing says whether a removed track finished (#6399)

`Broadcast.TracksEvent` gains `{ kind: "finished", name }`: the track left the listing because it finished. `{ kind: "removed", name }` now means it left unfinished. Handle both where you matched `"removed"`.
Expand Down
15 changes: 11 additions & 4 deletions js/net/src/ietf/publisher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,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);
Expand All @@ -580,9 +585,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);
}
}
}
Expand Down
19 changes: 19 additions & 0 deletions js/net/src/origin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2700,3 +2700,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();
}
});
9 changes: 9 additions & 0 deletions js/net/src/origin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,13 @@ class VersionedSignal<T> extends Signal<T> {
}
}

// 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
Expand Down Expand Up @@ -1232,6 +1239,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");

Expand Down Expand Up @@ -1343,6 +1351,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 = {
Expand Down
7 changes: 7 additions & 0 deletions rs/moq-net/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

### A listing says whether a removed track finished (#6399)

`broadcast::TracksEvent` gains `Finished { name }`: the track left the listing because its producer declared its end. `Removed { name }` now means it left unfinished (dropped or aborted without an end, or its route withdrawn). Handle both where you matched `Removed`.
Expand Down
15 changes: 11 additions & 4 deletions rs/moq-net/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
30 changes: 29 additions & 1 deletion rs/moq-net/src/model/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,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(())
}

/// What `scope` lets a route at `claim` serve: see [`RouteEntry::reach`].
fn reach(scope: &Patterns, claim: &Pattern) -> Vec<Pattern> {
scope
Expand Down Expand Up @@ -2165,7 +2174,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<broadcast::Producer, Error> {
let full = self.root.join(path.as_path()).to_owned();
Expand All @@ -2176,6 +2186,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);
}
Expand Down Expand Up @@ -2537,6 +2548,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<Self, Error> {
let requested = producer.root.join(prefix.as_path()).to_owned();
publish_path(&requested)?;
if requested.parts().count() > Path::MAX_PARTS {
return Err(BoundsExceeded.into());
}
Expand Down Expand Up @@ -13098,6 +13110,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();
Expand Down
Loading