From 8fd1c1716f2fbe068bd9bbc34058d03bf6677f39 Mon Sep 17 00:00:00 2001 From: oracola91 <118899664+oracola91@users.noreply.github.com> Date: Fri, 23 Oct 2026 11:58:52 +0300 Subject: [PATCH 1/5] PDF export drops javascript:, vbscript:, data: and network-share links A slide hyperlink from an untrusted deck became a PDF link whatever it pointed at. Script and data links, and links to another machine (UNC \\host\share, //host/share, file://host/...), are now left out of the PDF; the text stays. On Windows, opening a network path sends the user's NTLM credentials to that host. Web, mail, local file: and relative links are kept. The scheme is read the way a browser reads it: control characters dropped, leading spaces trimmed, any case. The slide show already refuses these links (safe_url), and cadcraft's PDF export drops script and data links. --- crates/pdf/src/lib.rs | 28 ++++++++++++++++++++++- crates/pdf/src/tests.rs | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) diff --git a/crates/pdf/src/lib.rs b/crates/pdf/src/lib.rs index 40d09c71f0..6d3f5f42a9 100644 --- a/crates/pdf/src/lib.rs +++ b/crates/pdf/src/lib.rs @@ -565,7 +565,7 @@ impl Exporter<'_> { slide.and_then(|s| page_of.get(&s)).map(|p| Target::Destination(XyzDestination::new(*p, Point::from_xy(0.0, 0.0)).into())) }; let target = match &l.link.action { - ClickAction::Url { url } => Some(Target::Action(Action::Link(LinkAction::new(url.clone())))), + ClickAction::Url { url } if exportable_url(url) => Some(Target::Action(Action::Link(LinkAction::new(url.clone())))), ClickAction::Slide { slide } => goto(pres.slides.iter().position(|x| x.id == *slide)), ClickAction::NextSlide => goto(Some(i + 1)), ClickAction::PreviousSlide => goto(i.checked_sub(1)), @@ -693,5 +693,31 @@ fn to_path(bp: &kurbo::BezPath) -> Option { pb.finish() } +/// Can a hyperlink from a (possibly untrusted) deck become a PDF link? Scripts (`javascript:`, +/// `vbscript:`), `data:` and paths to another machine (`\\host\share`, `//host/share`, +/// `file://host/...`) cannot: on Windows, opening a network path sends the user's NTLM credentials +/// to that host. Web, mail, local `file:` and relative links can. Read the way a browser reads a +/// URL: control characters dropped, leading spaces trimmed, any case. +fn exportable_url(url: &str) -> bool { + let u: String = url.chars().filter(|c| !c.is_ascii_control()).collect(); + let u = u.trim_start().replace('\\', "/"); + if u.starts_with("//") { + return false; + } + let Some((scheme, rest)) = u.split_once(':') else { return true }; + match scheme.to_ascii_lowercase().as_str() { + "javascript" | "vbscript" | "data" => false, + "file" => match rest.strip_prefix("//") { + // `file:///C:/...` and `file://localhost/...` are local; `file://host/...` and `file:////host/...` are not. + Some(p) => { + let (host, path) = p.split_once('/').unwrap_or((p, "")); + (host.is_empty() || host.eq_ignore_ascii_case("localhost")) && !path.starts_with('/') + } + None => true, + }, + _ => true, + } +} + #[cfg(test)] mod tests; diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rs index a17d461e68..ff349b4b1e 100644 --- a/crates/pdf/src/tests.rs +++ b/crates/pdf/src/tests.rs @@ -130,6 +130,55 @@ fn text_layer_links_and_bookmarks_survive_serialization() { } } +/// Links from an untrusted deck: scripts, `data:` and network shares (a UNC path leaks the user's +/// NTLM credentials on Windows) do not become PDF links; web, mail, local and relative links do. +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +#[cfg_attr(not(target_arch = "wasm32"), test)] +fn unsafe_url_links_are_not_exported() { + use deckcraft_model::text::{Action, Hyperlink}; + use deckcraft_model::{Shape, ShapeId, Xfrm}; + use hayro_syntax::object::{Array, Dict, String as PdfString}; + let safe = ["https://example.com/deck", "mailto:someone@example.com", "file:///C:/talks/notes.pdf", "notes.pdf"]; + let refused = [ + "javascript:alert(1)", + "\t JavaScript:alert(1)", + "java\nscript:alert(1)", + "vbscript:MsgBox(1)", + "data:text/html,", + "\\\\attacker.example\\share\\x", + "//attacker.example/share/x", + "file://attacker.example/share/x", + "file:////attacker.example/share/x", + ]; + let mut p = deck(1); + let slide = Arc::make_mut(&mut p.slides[0]); + slide.shapes = (0..) + .zip(safe.iter().chain(&refused)) + .map(|(i, url)| Shape { + id: ShapeId(9000 + i), + xfrm: Some(Xfrm::new(20.0, 20.0 + 38.0 * f64::from(i), 400.0, 30.0)), + click: Some(Hyperlink { + action: Action::Url { url: url.to_string() }, + tooltip: String::new(), + highlight_click: false, + sound: None, + stop_sound: false, + zoom_return: None, + }), + ..Default::default() + }) + .collect(); + let bytes = export(&p, &opts(PageLayout::Slides)).unwrap(); + let pdf = hayro_syntax::Pdf::new(bytes.clone()).unwrap(); + let annotations = pdf.pages()[0].raw().get::>(b"Annots").unwrap(); + let uris: Vec = annotations + .iter::>() + .filter_map(|a| a.get::>(b"A")?.get::>(b"URI")) + .map(|s| String::from_utf8_lossy(s.as_bytes()).into_owned()) + .collect(); + assert_eq!(uris, safe); +} + /// Build a small damaged derivative of our openly licensed last-resort font entirely in /// memory. Its naming/shaping tables still parse, but its missing head table prevents PDF /// embedding. No font bytes or vendor assets are stored as test fixtures. From 8c4907a6260ab3e3330f8d32b61b30474396cd2f Mon Sep 17 00:00:00 2001 From: oracola91 <118899664+oracola91@users.noreply.github.com> Date: Fri, 23 Oct 2026 13:53:24 +0300 Subject: [PATCH 2/5] PDF export also drops smb: links An smb://host/share link is a path to another machine too: opening it connects to that host (macOS and Linux file managers open these links). It is now left out of the PDF like the other network-share links, and the test covers it. --- crates/pdf/src/lib.rs | 8 ++++---- crates/pdf/src/tests.rs | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/pdf/src/lib.rs b/crates/pdf/src/lib.rs index 6d3f5f42a9..5683b675f4 100644 --- a/crates/pdf/src/lib.rs +++ b/crates/pdf/src/lib.rs @@ -695,9 +695,9 @@ fn to_path(bp: &kurbo::BezPath) -> Option { /// Can a hyperlink from a (possibly untrusted) deck become a PDF link? Scripts (`javascript:`, /// `vbscript:`), `data:` and paths to another machine (`\\host\share`, `//host/share`, -/// `file://host/...`) cannot: on Windows, opening a network path sends the user's NTLM credentials -/// to that host. Web, mail, local `file:` and relative links can. Read the way a browser reads a -/// URL: control characters dropped, leading spaces trimmed, any case. +/// `file://host/...`, `smb://host/...`) cannot: opening one connects to that host, which on Windows +/// sends the user's NTLM credentials. Web, mail, local `file:` and relative links can. Read the way +/// a browser reads a URL: control characters dropped, leading spaces trimmed, any case. fn exportable_url(url: &str) -> bool { let u: String = url.chars().filter(|c| !c.is_ascii_control()).collect(); let u = u.trim_start().replace('\\', "/"); @@ -706,7 +706,7 @@ fn exportable_url(url: &str) -> bool { } let Some((scheme, rest)) = u.split_once(':') else { return true }; match scheme.to_ascii_lowercase().as_str() { - "javascript" | "vbscript" | "data" => false, + "javascript" | "vbscript" | "data" | "smb" => false, "file" => match rest.strip_prefix("//") { // `file:///C:/...` and `file://localhost/...` are local; `file://host/...` and `file:////host/...` are not. Some(p) => { diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rs index ff349b4b1e..74e2daf043 100644 --- a/crates/pdf/src/tests.rs +++ b/crates/pdf/src/tests.rs @@ -149,6 +149,7 @@ fn unsafe_url_links_are_not_exported() { "//attacker.example/share/x", "file://attacker.example/share/x", "file:////attacker.example/share/x", + "smb://attacker.example/share/x", ]; let mut p = deck(1); let slide = Arc::make_mut(&mut p.slides[0]); From afb52aeef32255d71969b3de824dd396b227b0f9 Mon Sep 17 00:00:00 2001 From: oracola91 <118899664+oracola91@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:04:02 +0300 Subject: [PATCH 3/5] PDF export also drops search: and search-ms: links Windows Search's search: and search-ms: links can name a folder on another machine through crumb=location:, and opening one connects to that host and sends the user's NTLM credentials. They are now left out of the PDF like the other network-share links, and the test covers both. --- crates/pdf/src/lib.rs | 5 +++-- crates/pdf/src/tests.rs | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/pdf/src/lib.rs b/crates/pdf/src/lib.rs index 5683b675f4..a50d0f21b2 100644 --- a/crates/pdf/src/lib.rs +++ b/crates/pdf/src/lib.rs @@ -695,7 +695,8 @@ fn to_path(bp: &kurbo::BezPath) -> Option { /// Can a hyperlink from a (possibly untrusted) deck become a PDF link? Scripts (`javascript:`, /// `vbscript:`), `data:` and paths to another machine (`\\host\share`, `//host/share`, -/// `file://host/...`, `smb://host/...`) cannot: opening one connects to that host, which on Windows +/// `file://host/...`, `smb://host/...`, and Windows Search's `search:` and `search-ms:`, whose +/// `crumb=location:` can name one) cannot: opening one connects to that host, which on Windows /// sends the user's NTLM credentials. Web, mail, local `file:` and relative links can. Read the way /// a browser reads a URL: control characters dropped, leading spaces trimmed, any case. fn exportable_url(url: &str) -> bool { @@ -706,7 +707,7 @@ fn exportable_url(url: &str) -> bool { } let Some((scheme, rest)) = u.split_once(':') else { return true }; match scheme.to_ascii_lowercase().as_str() { - "javascript" | "vbscript" | "data" | "smb" => false, + "javascript" | "vbscript" | "data" | "smb" | "search" | "search-ms" => false, "file" => match rest.strip_prefix("//") { // `file:///C:/...` and `file://localhost/...` are local; `file://host/...` and `file:////host/...` are not. Some(p) => { diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rs index 74e2daf043..5f7d09f522 100644 --- a/crates/pdf/src/tests.rs +++ b/crates/pdf/src/tests.rs @@ -150,6 +150,8 @@ fn unsafe_url_links_are_not_exported() { "file://attacker.example/share/x", "file:////attacker.example/share/x", "smb://attacker.example/share/x", + "search-ms:query=x&crumb=location:\\\\attacker.example\\share", + "search:query=x&crumb=location:\\\\attacker.example\\share", ]; let mut p = deck(1); let slide = Arc::make_mut(&mut p.slides[0]); From 274b62600711399af5145174b0d992dcce3fb961 Mon Sep 17 00:00:00 2001 From: oracola91 <118899664+oracola91@users.noreply.github.com> Date: Fri, 23 Oct 2026 20:16:37 +0300 Subject: [PATCH 4/5] Test: every link of the unsafe-link test sits on the slide The last links started below the 540 pt slide. They were still exported, as zero-height annotations at the page edge, so the test worked, but only because of that. With all 16 links on the slide the test no longer depends on how off-page links are handled. --- crates/pdf/src/tests.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rs index 5f7d09f522..05609ce772 100644 --- a/crates/pdf/src/tests.rs +++ b/crates/pdf/src/tests.rs @@ -159,7 +159,7 @@ fn unsafe_url_links_are_not_exported() { .zip(safe.iter().chain(&refused)) .map(|(i, url)| Shape { id: ShapeId(9000 + i), - xfrm: Some(Xfrm::new(20.0, 20.0 + 38.0 * f64::from(i), 400.0, 30.0)), + xfrm: Some(Xfrm::new(20.0, 20.0 + 32.0 * f64::from(i), 400.0, 26.0)), click: Some(Hyperlink { action: Action::Url { url: url.to_string() }, tooltip: String::new(), From 920925abaeb24a5590784514c77a85562576978c Mon Sep 17 00:00:00 2001 From: oracola91 <118899664+oracola91@users.noreply.github.com> Date: Sat, 24 Oct 2026 13:31:06 +0300 Subject: [PATCH 5/5] PDF export keeps only the links the slide show opens A denylist can't keep up with OS protocol handlers: ms-msdt:, ms-word: with a share path, ldap: and file:///%5C%5Chost/share still went into exported PDFs. PDF export now writes a URL link only when safe_url allows it, the check the slide show already uses on a click: http, https and mailto. Links between slides are unchanged, and any other link's text stays on the page without the link. safe_url moves from deckcraft-anim to deckcraft-model, which both crates use; deckcraft_anim::safe_url stays as a re-export. Local file: and relative links are left out for now, as asked in review. --- crates/anim/src/show.rs | 14 ++------------ crates/model/src/tests.rs | 24 ++++++++++++++++++++++++ crates/model/src/text.rs | 13 +++++++++++++ crates/pdf/src/lib.rs | 33 ++++----------------------------- crates/pdf/src/tests.rs | 8 +++++++- 5 files changed, 50 insertions(+), 42 deletions(-) diff --git a/crates/anim/src/show.rs b/crates/anim/src/show.rs index a1117c6277..403f05a0ab 100644 --- a/crates/anim/src/show.rs +++ b/crates/anim/src/show.rs @@ -29,18 +29,8 @@ pub enum ShowAction { Exit, } -/// Can a link from a (possibly untrusted) deck be opened outside the show? Only web pages and -/// mail: `file:`, `javascript:`, relative paths and other schemes (OS protocol handlers) are not -/// opened on a click. -pub fn safe_url(url: &str) -> bool { - let u = url.trim(); - let Some((scheme, rest)) = u.split_once(':') else { return false }; - match scheme.to_ascii_lowercase().as_str() { - "http" | "https" => rest.starts_with("//") && rest.len() > 2, - "mailto" => !rest.is_empty(), - _ => false, - } -} +// Which links the show opens on a click; PDF export writes the same ones. +pub use deckcraft_model::text::safe_url; /// What a clicked link does in the show (`ShowState::follow`). #[derive(Clone, Debug, PartialEq, Eq)] diff --git a/crates/model/src/tests.rs b/crates/model/src/tests.rs index bc3817d91d..4019a117a9 100644 --- a/crates/model/src/tests.rs +++ b/crates/model/src/tests.rs @@ -294,3 +294,27 @@ fn table_text_takes_the_masters_other_style_and_shapes_the_default_text_style() assert_eq!(pt(&Shape { text: Some(body.clone()), ..Default::default() }), Some(26.0), "a shape"); assert_eq!(pt(&Shape { text: Some(body), text_box: true, ..Default::default() }), Some(26.0), "a text box"); } + +#[test] +fn only_web_and_mail_links_are_safe_to_open() { + use crate::text::safe_url; + for url in ["https://example.com", " HTTP://example.com/x", "mailto:someone@example.com"] { + assert!(safe_url(url), "{url}"); + } + let refused = [ + "https://", + "mailto:", + "file:///C:/notes.pdf", + "notes.pdf", + "javascript:alert(1)", + "ms-msdt:/id PCWDiagnostic", + "ldap://attacker.example/x", + "//attacker.example/share", + "\\\\attacker.example\\share", + "smb://attacker.example/share", + "search-ms:query=x", + ]; + for url in refused { + assert!(!safe_url(url), "{url}"); + } +} diff --git a/crates/model/src/text.rs b/crates/model/src/text.rs index 4b81412971..17d606de7c 100644 --- a/crates/model/src/text.rs +++ b/crates/model/src/text.rs @@ -328,6 +328,19 @@ pub enum Action { PlayMedia, } +/// Can a link from a (possibly untrusted) deck be opened outside it, by the slide show or by +/// whoever opens an exported file? Only web pages and mail: `file:`, `javascript:`, relative paths +/// and other schemes (OS protocol handlers, network shares) are not. +pub fn safe_url(url: &str) -> bool { + let u = url.trim(); + let Some((scheme, rest)) = u.split_once(':') else { return false }; + match scheme.to_ascii_lowercase().as_str() { + "http" | "https" => rest.starts_with("//") && rest.len() > 2, + "mailto" => !rest.is_empty(), + _ => false, + } +} + fn custom_show_returns() -> bool { true } diff --git a/crates/pdf/src/lib.rs b/crates/pdf/src/lib.rs index a50d0f21b2..1b80ad6aa0 100644 --- a/crates/pdf/src/lib.rs +++ b/crates/pdf/src/lib.rs @@ -17,7 +17,7 @@ use craft_pdf::write::{self, Metadata, Writer, backend as krilla}; use deckcraft_fonts::FontDb; use deckcraft_model::Presentation; -use deckcraft_model::text::Action as ClickAction; +use deckcraft_model::text::{Action as ClickAction, safe_url}; use deckcraft_render::{PlacedText, RenderOpts}; use krilla::action::{Action, LinkAction}; use krilla::annotation::{Annotation, LinkAnnotation, Target}; @@ -565,7 +565,9 @@ impl Exporter<'_> { slide.and_then(|s| page_of.get(&s)).map(|p| Target::Destination(XyzDestination::new(*p, Point::from_xy(0.0, 0.0)).into())) }; let target = match &l.link.action { - ClickAction::Url { url } if exportable_url(url) => Some(Target::Action(Action::Link(LinkAction::new(url.clone())))), + // Only the links the slide show opens (web and mail): a reader of the file gets the rest + // as plain text. + ClickAction::Url { url } if safe_url(url) => Some(Target::Action(Action::Link(LinkAction::new(url.clone())))), ClickAction::Slide { slide } => goto(pres.slides.iter().position(|x| x.id == *slide)), ClickAction::NextSlide => goto(Some(i + 1)), ClickAction::PreviousSlide => goto(i.checked_sub(1)), @@ -693,32 +695,5 @@ fn to_path(bp: &kurbo::BezPath) -> Option { pb.finish() } -/// Can a hyperlink from a (possibly untrusted) deck become a PDF link? Scripts (`javascript:`, -/// `vbscript:`), `data:` and paths to another machine (`\\host\share`, `//host/share`, -/// `file://host/...`, `smb://host/...`, and Windows Search's `search:` and `search-ms:`, whose -/// `crumb=location:` can name one) cannot: opening one connects to that host, which on Windows -/// sends the user's NTLM credentials. Web, mail, local `file:` and relative links can. Read the way -/// a browser reads a URL: control characters dropped, leading spaces trimmed, any case. -fn exportable_url(url: &str) -> bool { - let u: String = url.chars().filter(|c| !c.is_ascii_control()).collect(); - let u = u.trim_start().replace('\\', "/"); - if u.starts_with("//") { - return false; - } - let Some((scheme, rest)) = u.split_once(':') else { return true }; - match scheme.to_ascii_lowercase().as_str() { - "javascript" | "vbscript" | "data" | "smb" | "search" | "search-ms" => false, - "file" => match rest.strip_prefix("//") { - // `file:///C:/...` and `file://localhost/...` are local; `file://host/...` and `file:////host/...` are not. - Some(p) => { - let (host, path) = p.split_once('/').unwrap_or((p, "")); - (host.is_empty() || host.eq_ignore_ascii_case("localhost")) && !path.starts_with('/') - } - None => true, - }, - _ => true, - } -} - #[cfg(test)] mod tests; diff --git a/crates/pdf/src/tests.rs b/crates/pdf/src/tests.rs index 05609ce772..f29935f68e 100644 --- a/crates/pdf/src/tests.rs +++ b/crates/pdf/src/tests.rs @@ -138,8 +138,14 @@ fn unsafe_url_links_are_not_exported() { use deckcraft_model::text::{Action, Hyperlink}; use deckcraft_model::{Shape, ShapeId, Xfrm}; use hayro_syntax::object::{Array, Dict, String as PdfString}; - let safe = ["https://example.com/deck", "mailto:someone@example.com", "file:///C:/talks/notes.pdf", "notes.pdf"]; + let safe = ["https://example.com/deck", "mailto:someone@example.com"]; let refused = [ + "file:///C:/talks/notes.pdf", + "notes.pdf", + "ms-msdt:/id PCWDiagnostic /skip force", + "ms-word:ofe|u|\\\\attacker.example\\share\\x.docx", + "ldap://attacker.example/x", + "file:///%5C%5Cattacker.example/share/x", "javascript:alert(1)", "\t JavaScript:alert(1)", "java\nscript:alert(1)",