diff --git a/crates/core/src/share.rs b/crates/core/src/share.rs index 1261dbc..5466a69 100644 --- a/crates/core/src/share.rs +++ b/crates/core/src/share.rs @@ -412,6 +412,30 @@ const SLASH_LOOKALIKES: &[char] = &[ '\u{2215}', '\u{2044}', '\u{29F8}', '\u{29F9}', '\u{2216}', '\u{29F5}', '\u{2571}', '\u{2572}', ]; +/// Unicode's Default_Ignorable_Code_Point (DerivedCoreProperties.txt, Unicode 15). +fn default_ignorable(c: char) -> bool { + matches!( + c as u32, + 0x00AD + | 0x034F + | 0x061C + | 0x115F..=0x1160 + | 0x17B4..=0x17B5 + | 0x180B..=0x180F + | 0x200B..=0x200F + | 0x202A..=0x202E + | 0x2060..=0x206F + | 0x3164 + | 0xFE00..=0xFE0F + | 0xFEFF + | 0xFFA0 + | 0xFFF0..=0xFFF8 + | 0x1BCA0..=0x1BCA3 + | 0x1D173..=0x1D17A + | 0xE0000..=0xE0FFF + ) +} + /// Decode `%xx` escapes once. `None` for a broken escape. fn percent_decode(raw: &str) -> Option> { let b = raw.as_bytes(); @@ -444,7 +468,8 @@ fn percent_decode(raw: &str) -> Option> { /// - any encoded character that NFKC normalisation turns into something containing `/`, `\`, /// `;`, `?`, `#`, `%` or a control character (fullwidth and small forms), and the slash /// look-alikes NFKC leaves alone ([`SLASH_LOOKALIKES`]); -/// - a segment that NFKC turns into only dots or nothing, after trimming whitespace (two-dot +/// - a segment that NFKC turns into only dots or nothing, after dropping default-ignorable +/// characters and combining marks and trimming whitespace (two-dot /// leaders, ellipses, fullwidth dots, look-alike spaces); look-alike dots and spaces inside a /// name with other characters (`Wait….pdf`, an ideographic space) are fine; /// - a segment of only dots, also with `;params` (`..;x`, `..%3b`), and any segment that is @@ -493,9 +518,19 @@ pub fn path_within(prefix: &str, raw_path: &str) -> bool { if seg.is_ascii() { continue; // the raw checks below cover ASCII segments } + // Invisible characters (default-ignorable code points, combining marks) do not count: + // `\u{200B}..` is `..` to a server that drops them. let n: String = seg.nfkc().collect(); - let name = n.split(';').next().unwrap_or("").trim(); - if name.chars().all(|c| c == '.') { + let visible: String = n + .split(';') + .next() + .unwrap_or("") + .chars() + .filter(|c| { + !default_ignorable(*c) && !unicode_normalization::char::is_combining_mark(*c) + }) + .collect(); + if visible.trim().chars().all(|c| c == '.') { return false; } } diff --git a/crates/core/tests/share.rs b/crates/core/tests/share.rs index 6b4f7e1..f6acff0 100644 --- a/crates/core/tests/share.rs +++ b/crates/core/tests/share.rs @@ -363,6 +363,8 @@ fn paths_under_the_prefix_are_within() { ("/a", "/a/my%20file.pdf"), ("/a", "/a/a+b"), ("/a", "/a/caf%C3%A9"), + ("/a", "/a/cafe%CC%81"), + ("/a", "/a/%E3%80%80photo%E3%80%80album"), ("/a", "/a/e%CC%81"), ("/a", "/a/%E2%80%93"), ("/a", "/a/%E6%97%85%E8%A1%8C"), @@ -458,6 +460,23 @@ fn no_path_trick_escapes_the_prefix() { ("/a", "/a/x%e2%81%84y"), ("/a", "/a/%+f/b"), ("/a", "/a/%-1/b"), + // QC fix round 4: dot-only segments hidden by invisible characters. + ("/a", "/a/%e2%80%8b../b"), + ("/a", "/a/%ef%bb%bf../b"), + ("/a", "/a/%c2%ad../b"), + ("/a", "/a/%cc%81../b"), + ("/a", "/a/%e2%80%a4.%e2%80%8b/b"), + ("/a", "/a/%e2%81%a0%e2%80%a5/b"), + ("/a", "/a/..%cc%81/b"), + ("/a", "/a/%e3%80%80../b"), + ("/a", "/a/%ef%bc%8e%ef%bc%8e/b"), + ("/a", "/a/%e2%80%a5%3bx/b"), + ("/a", "/a/%ef%bc%85/b"), + ("/a", "/a/x%ef%bc%8fy"), + ("/a", "/a/%e2%80%a4%09/b"), + ("/a", "/a/%ef%b9%a8"), + ("/a", "/a/%e2%88%96"), + ("/a", "/a/%e2%80%8b/b"), ]; for (prefix, path) in cases { assert!(