From af4270fb6da8762a538cda4ea1aa6e831630f3a2 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 21 Oct 2026 18:19:55 -0400 Subject: [PATCH] security: reject shell metacharacters in opened web links Feed notice links and release-note hyperlinks are forwarded to the system opener when clicked. The pinned webbrowser crate's WSL fallback passes the URL to cmd.exe /c start while escaping only ^ and &, so a pipe (or other metacharacter) in an otherwise valid https URL becomes a command separator and runs a Windows command (CWE-78). Rather than depend on the third-party opener to neutralise the URL, refuse any link containing a shell/cmd metacharacter at the validation boundary, where a real https web link never needs one: - release::safe_web_link (release notes) now rejects shell metacharacters via the shared release::is_shell_meta, on top of the existing scheme/host/whitespace checks. - The feed notice link filter routes through the same rule and also rejects control characters. Addresses finding: widgets.rs/webbrowser WSL fallback CWE-78. --- crates/core/src/feed.rs | 16 +++++++++++----- crates/core/src/release.rs | 31 +++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/crates/core/src/feed.rs b/crates/core/src/feed.rs index 4d24d8f2..5b14c796 100644 --- a/crates/core/src/feed.rs +++ b/crates/core/src/feed.rs @@ -407,9 +407,13 @@ impl RawNotice { if self.title.trim().is_empty() && self.body.trim().is_empty() { return None; } - let link = self - .maybe_web_link - .filter(|l| (l.starts_with("https://") || l.starts_with("http://")) && l.len() <= 2000 && !l.chars().any(char::is_whitespace)); + // The link may reach the system opener (whose WSL fallback shells out), so refuse any + // shell/cmd metacharacter or control character in it as well as whitespace (CWE-78). + let link = self.maybe_web_link.filter(|l| { + (l.starts_with("https://") || l.starts_with("http://")) + && l.len() <= 2000 + && !l.chars().any(|c| c.is_whitespace() || c.is_control() || release::is_shell_meta(c)) + }); Some(Notice { id: format!("{kind}:{}:{}", self.created_at.as_deref().unwrap_or(""), self.title.trim()), title: truncate(self.title.trim(), 200), @@ -612,7 +616,8 @@ mod tests { "\"alerts\": []", r#""alerts": [ {"title": "Security update", "body": "Update PdfCraft now.", "maybe_web_link": "https://getartcraft.com/security", "created_at": null}, - {"title": "Bad link", "body": "x", "maybe_web_link": "javascript:alert(1)"}]"#, + {"title": "Bad link", "body": "x", "maybe_web_link": "javascript:alert(1)"}, + {"title": "Shell link", "body": "x", "maybe_web_link": "https://getartcraft.com/a|calc.exe"}]"#, ) .replace( "\"app_renames\": []", @@ -620,9 +625,10 @@ mod tests { "new_name_lower": "docucraft", "description": "Same app, new name.", "renamed_at": "2026-10-09T08:00:00Z"}]"#, ); let feed = Feed::parse(&with_notices).unwrap(); - assert_eq!(feed.alerts.len(), 2); + assert_eq!(feed.alerts.len(), 3); assert_eq!(feed.alerts[0].link.as_deref(), Some("https://getartcraft.com/security")); assert_eq!(feed.alerts[1].link, None, "only web links are kept"); + assert_eq!(feed.alerts[2].link, None, "a link with shell metacharacters is dropped"); let titles: Vec<&str> = feed.announcements.iter().map(|n| n.title.as_str()).collect(); assert_eq!(titles, ["New: CADCraft 1.0", "PdfCraft is now DocuCraft"]); // Ids are stable across parses, so dismissals stick. diff --git a/crates/core/src/release.rs b/crates/core/src/release.rs index f975d176..6197b968 100644 --- a/crates/core/src/release.rs +++ b/crates/core/src/release.rs @@ -61,11 +61,28 @@ fn is_hex64(s: &str) -> bool { } /// Whether `url` is safe to hand to the system browser from untrusted text (release notes): -/// `https` only, a host, no user-info, no spaces or control characters. +/// `https` only, a host, no user-info, no spaces or control characters, and no shell metacharacters. +/// +/// The system opener is not always a direct `open`: the pinned `webbrowser` crate's WSL fallback +/// passes the URL to `cmd.exe /c start` while escaping only `^` and `&`, so a character like `|` +/// in an otherwise valid URL becomes a command separator (CWE-78). Because a legitimate +/// `https://` web link never needs these characters unescaped, we refuse any URL that contains a +/// shell/cmd metacharacter rather than rely on the opener to neutralise it. pub fn safe_web_link(url: &str) -> bool { let Some(rest) = url.strip_prefix("https://") else { return false }; let authority = rest.split(['/', '?', '#']).next().unwrap_or_default(); - url.len() <= 2000 && !authority.is_empty() && !authority.contains(['@', '\\']) && !url.chars().any(|c| c.is_control() || c.is_whitespace()) + url.len() <= 2000 + && !authority.is_empty() + && !authority.contains(['@', '\\']) + && !url.chars().any(|c| c.is_control() || c.is_whitespace()) + && !url.chars().any(is_shell_meta) +} + +/// Characters a command interpreter (POSIX shells or `cmd.exe`) may treat specially. A real +/// `https` URL never needs any of them unescaped in a browser-opened link. `%` matters because +/// `cmd.exe` expands `%NAME%` references, and an expanded value could itself carry metacharacters. +pub fn is_shell_meta(c: char) -> bool { + matches!(c, '|' | '&' | ';' | '<' | '>' | '(' | ')' | '$' | '`' | '"' | '\'' | '^' | '!' | '*' | '%' | '{' | '}' | '[' | ']') } /// The prefix every download of `repo` must start with. @@ -216,6 +233,16 @@ mod tests { "https://example.com/a b", "https://example.com/\nx", "https:///path", + // Shell/cmd metacharacters: the WSL opener fallback shells out, so these must be + // refused even inside an otherwise valid https URL (CWE-78). + "https://example.com/a|calc", + "https://example.com/p?x=1&y=2", + "https://example.com/`id`", + "https://example.com/$(whoami)", + "https://example.com/a;b", + "https://example.com/a>b", + "https://example.com/%COMSPEC%", + "https://example.com/%PATH%", ] { assert!(!safe_web_link(bad), "{bad:?}"); }