From bf2a7d1e98015eb9de1915d492d465f5f9e70585 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= Date: Wed, 18 Nov 2026 22:36:11 +0000 Subject: [PATCH] fix(core): match see_also URLs with an uppercase scheme see_also_local_id stripped the scheme case-sensitively before lowercasing, so an uppercase scheme (HTTP://...) survived the strip and the host prefix never matched. A see_also link to a hidden bug written that way was served unscrubbed, disclosing the bug (I14). Lowercase first, then strip the scheme; same for the base-URL strip in embedded_local_ids. --- crates/bugwarden-core/src/guard.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/crates/bugwarden-core/src/guard.rs b/crates/bugwarden-core/src/guard.rs index 72d5928..e3175d0 100644 --- a/crates/bugwarden-core/src/guard.rs +++ b/crates/bugwarden-core/src/guard.rs @@ -562,11 +562,16 @@ impl Guard { // see_also with the host as the user typed it, so scheme and case // vary freely for the same instance. An instance reachable under a // second hostname is still missed — recorded in I14, not fixed here. + // Lowercase FIRST: the scheme strip is case-sensitive, so an + // uppercase scheme ("HTTP://...") would survive it and the host + // prefix would never match, leaving a link to a hidden bug + // unscrubbed (I14). let strip_scheme = |u: &str| { - u.trim() + let lower = u.trim().to_ascii_lowercase(); + lower .trim_start_matches("https://") .trim_start_matches("http://") - .to_ascii_lowercase() + .to_string() }; let base = strip_scheme(base_url); let base = base.trim_end_matches('/'); @@ -874,11 +879,15 @@ impl Guard { /// sits in the text. The whole-value match alone misses a /// second URL, so each local marker is scanned for. fn embedded_local_ids(value: &str, base_url: &str) -> BTreeSet { + // Lowercase first, as in `see_also_local_id`: the scheme strip is + // case-sensitive, so an uppercase scheme in the base URL would + // survive it and no embedded URL would ever match. let strip = |u: &str| { - u.trim() + let lower = u.trim().to_ascii_lowercase(); + lower .trim_start_matches("https://") .trim_start_matches("http://") - .to_ascii_lowercase() + .to_string() }; let base = strip(base_url); let base = base.trim_end_matches('/'); @@ -2528,6 +2537,11 @@ mod tests { "http://bugzilla.example.com/show_bug.cgi?id=7", "https://BUGZILLA.EXAMPLE.COM/show_bug.cgi?id=7", "https://bugzilla.example.com/show_bug.cgi?id=7", + // An uppercase SCHEME must match too: the scheme strip is + // case-sensitive, so without lowercasing first it survives and + // the host prefix never matches (I14 bypass). + "HTTP://bugzilla.example.com/show_bug.cgi?id=7", + "HTTPS://BUGZILLA.EXAMPLE.COM/show_bug.cgi?id=7", ] { assert_eq!( Guard::see_also_local_id(entry, BASE),