test(tests): R4.5 export-side security cases; ledger rows of the writer cases point at cargo (only the R4.7 compare rows pending)

This commit is contained in:
bchanot committed 2026-10-18 23:24:37 +02:00
1 parent 50c8fe0b33
commit ba6ac078be
3 files changed
+132 -66

No files matched your search

+53
View File
@@ -751,3 +751,56 @@ fn restoration_round_trip_loses_nothing() {
}
}
}
/// The export-side security cases of the TypeScript suite: a hostile SVG asset in the
/// snapshot is `snapshot_invalid` before any page; a URL that would close a literal string
/// never reaches the file (the schema refuses it, and the link sink writes hex ASCII only);
/// a PNG logo the gate refuses fails alone with `logo_failed`.
#[test]
fn export_side_security_cases_hold() {
use faunosteo_core::pdf::write::input::{ExportWarning, LogoSlot, check_input};
let r3 = fixture("pdf/r3/demo.fr.logos.pdf");
let envelope = envelope_of(&r3);
// Hostile asset: an SVG with a doctype (the reader refuses it; the TS sanitiser did too).
let mut hostile = envelope.clone();
let doctype = std::fs::read_to_string(
repo_root().join("crates/core/tests/fixtures/svg/hostile/doctype-entities.svg"),
)
.unwrap();
hostile["sheetSnapshot"]["assets"][0]["svg"] = Value::String(doctype);
let err = check_input(input_from(&hostile)).err().unwrap();
assert_eq!(err.kind.as_str(), "snapshot_invalid");
assert!(err.detail.starts_with("asset "), "{}", err.detail);
// URL injection: refused by the schema; the sink is hex ASCII for the accepted ones.
let mut injected = envelope.clone();
injected["branding"]["siteUrl"] =
Value::String("https://a.b/) /Next << /S /JavaScript >>".to_owned());
assert_eq!(
check_input(input_from(&injected)).err().unwrap().detail,
"branding"
);
let text = String::from_utf8_lossy(&stub_run("demo", "fr", "logos").r4).into_owned();
assert!(!text.contains("/URI ("), "URIs are written as hex strings");
assert!(
text.contains(&format!(
"/URI <{}>",
"https://faunosteo.com"
.bytes()
.map(|b| format!("{b:02x}"))
.collect::<String>()
))
);
// A refused PNG logo: the slot fails alone, the export completes with the warning.
let mut bad_logo = envelope.clone();
bad_logo["branding"]["headerLogo"] = json!({ "kind": "png", "base64": "iVBORw0KGgo=" });
let input = input_from(&bad_logo);
let rasters = stub_rasters(&input, &base64(TWO_BY_ONE_PNG));
let result = export_pdf(input, &rasters).unwrap();
assert_eq!(
result.warnings,
vec![ExportWarning::LogoFailed {
slot: LogoSlot::HeaderLogo
}]
);
assert!(read_attached_document(&result.pdf, ProbeLimits::PRODUCTION).is_ok());
}