Skip to content
Merged
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
45 changes: 41 additions & 4 deletions pkgs/id/src/app_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@
//! `is_safe_web_path` now rejects empty segments, so route `/`
//! (no non-empty segment), a trailing slash (`/app/`), and
//! doubled separators (`/a//b`) all fail the manifest gate for
//! `route` and `socket` alike. `/` is additionally a
//! host-registered route (disposition 6). Ordinary spellings
//! `route` and `socket` alike. Dot segments are rejected on the
//! same rule (#5427): `/a/./b`, `/./a`, and `/a/.` normalize onto
//! other paths, so they are alternate spellings, not new routes.
//! `/` is additionally a host-registered route (disposition 6). Ordinary spellings
//! (`/tic-tac-toe`, `/ws/world`) are unchanged.
//! 4. **App-`id` uniqueness.** Structural, no extra check added:
//! `app.id` must equal the folder (entry) name, and one
Expand Down Expand Up @@ -261,12 +263,12 @@ pub fn parse_app_manifest(source: &str, folder_name: &str) -> Result<AppManifest
);
ensure!(
is_safe_web_path(&web.route),
"interfaces.web.route must be an absolute path without traversal or empty segments, whitespace, ? or #"
"interfaces.web.route must be an absolute path without traversal, empty or dot segments, whitespace, ? or #"
);
if let Some(socket) = &web.socket {
ensure!(
is_safe_web_path(socket),
"interfaces.web.socket must be an absolute path without traversal or empty segments, whitespace, ? or #"
"interfaces.web.socket must be an absolute path without traversal, empty or dot segments, whitespace, ? or #"
);
}
}
Expand Down Expand Up @@ -429,6 +431,12 @@ fn is_safe_web_path(path: &str) -> bool {
// segment, so `/` itself, a trailing slash, and doubled
// separators are rejected, not just traversal segments.
&& !path.split('/').skip(1).any(|segment| segment.is_empty())
// Dot segments (#5427): a `.` segment is the remaining RFC 3986
// dot segment -- `/a/./b`, `/./a`, and `/a/.` pass the checks
// above but normalize onto `/a/b`, `/a`, and `/a/`, so one
// normalized path would pass as two distinct routes/sockets
// past the exact-string uniqueness checks downstream.
&& !path.split('/').skip(1).any(|segment| segment == ".")
}

/// One consistent list-entry rule for manifest string lists
Expand Down Expand Up @@ -581,6 +589,35 @@ route = "/tic-tac-toe"
assert!(error.to_string().contains("interfaces.web.socket"));
}

#[test]
fn test_web_route_dot_segments_are_rejected() {
// #5427: a `.` segment is an alternate spelling of the path
// without it (RFC 3986 remove_dot_segments), so it fails the
// shape rule for route and socket alike, while a dotted name
// that is not a whole segment stays legal.
for route in ["/./tic-tac-toe", "/tic-tac-toe/./x", "/tic-tac-toe/."] {
let source =
MANIFEST.replace("route = \"/tic-tac-toe\"", &format!("route = {route:?}"));
let error = parse_app_manifest(&source, "tic-tac-toe").unwrap_err();
assert!(
error.to_string().contains("interfaces.web.route"),
"route {route:?} rejection names the field: {error:#}"
);
}
let dot_socket = MANIFEST.replace(
"route = \"/tic-tac-toe\"",
"route = \"/tic-tac-toe\"\nsocket = \"/ws/./world\"",
);
let error = parse_app_manifest(&dot_socket, "tic-tac-toe").unwrap_err();
assert!(error.to_string().contains("interfaces.web.socket"));

let dotted_names = MANIFEST.replace(
"route = \"/tic-tac-toe\"",
"route = \"/tic-tac-toe\"\nsocket = \"/ws/world.min\"",
);
assert!(parse_app_manifest(&dotted_names, "tic-tac-toe").is_ok());
}

#[test]
fn checked_in_tic_tac_toe_manifest_remains_valid() {
let path = Path::new(env!("CARGO_MANIFEST_DIR")).join("apps/tic-tac-toe/app.toml");
Expand Down
Loading