fix(anatomy): V1-2.2 review findings, PIs and HTML refused, bounds
Security audit (PASS, 2 MEDIUM, 2 LOW) and verifier (ECARTS 6) on
741c25c: processing instructions and HTML fetchers refused, active
content under a long title classified, linear review groups, full
fixpoint check, bounded preview drawings, missing cap fixtures and
property checks, record wordings.
This commit is contained in:
1 parent
741c25c464
commit
8294d5471c
15 files changed
+448
-72
No files matched your search
@@ -590,7 +590,42 @@ fn random_command(doc: &AnatomicalSheetDocument, rng: &mut Rng, counter: &mut us
|
||||
.iter()
|
||||
.filter(|k| matches!(k, ElementKey::Finding { path, .. } if path.len() < 8))
|
||||
.collect();
|
||||
match rng.below(9) {
|
||||
match rng.below(12) {
|
||||
9 => {
|
||||
let view = rng.pick(&doc.views).cloned();
|
||||
match view {
|
||||
Some(view) => {
|
||||
let mut value = serde_json::to_value(&view).unwrap();
|
||||
if value["view_box"].is_object() {
|
||||
value["view_box"]["width"] = json!(1 + rng.below(5));
|
||||
} else {
|
||||
value["svg_asset_id"] =
|
||||
json!(format!("11111111-2222-4333-8444-{:012}", rng.below(3)));
|
||||
}
|
||||
json!({ "op": "update", "key": { "kind": "view", "id": view.id() }, "element": { "kind": "view", "value": value } })
|
||||
}
|
||||
None => json!({ "op": "remove", "key": { "kind": "sheet" } }),
|
||||
}
|
||||
}
|
||||
10 => match rng.below(3) {
|
||||
0 => {
|
||||
json!({ "op": "insert", "element": { "kind": "reference", "value": { "id": id, "type": "web", "citation": id } } })
|
||||
}
|
||||
1 => {
|
||||
json!({ "op": "remove", "key": { "kind": "reference", "id": rng.pick(&doc.references).map(|r| r.id.clone()).unwrap_or_default() } })
|
||||
}
|
||||
_ => {
|
||||
json!({ "op": "move", "key": { "kind": "zone", "id": rng.pick(&doc.finding_zones).map(|z| z.id.clone()).unwrap_or_default() }, "position": rng.below(3) })
|
||||
}
|
||||
},
|
||||
11 => {
|
||||
let zone = rng
|
||||
.pick(&doc.finding_zones)
|
||||
.map(|z| z.id.clone())
|
||||
.unwrap_or_default();
|
||||
json!({ "op": "update", "key": { "kind": "zone", "id": zone },
|
||||
"element": { "kind": "zone", "value": { "id": zone, "name": name("Zone renommée"), "categories": [] } } })
|
||||
}
|
||||
0 => {
|
||||
json!({ "op": "insert", "position": rng.below(2), "element": { "kind": "annotation", "value": {
|
||||
"id": id, "kind": "point", "view_id": view, "category_id": "c", "laterality": "left",
|
||||
@@ -738,7 +773,7 @@ fn check_command(
|
||||
"{raw}"
|
||||
);
|
||||
}
|
||||
"update" => {
|
||||
"update" if before.contains_key(&key()) => {
|
||||
let key = key();
|
||||
let expected = if changes == Some(&json!(true)) {
|
||||
ReviewStatus::ToConfirm
|
||||
@@ -775,8 +810,28 @@ fn check_command(
|
||||
"{raw}"
|
||||
);
|
||||
}
|
||||
"mark_reviewed" => {
|
||||
let ElementKey::Zone { id } = key() else {
|
||||
unreachable!()
|
||||
};
|
||||
for (k, status) in after {
|
||||
let inside = matches!(k, ElementKey::Finding { zone_id, .. } if *zone_id == id);
|
||||
let expected = if inside {
|
||||
ReviewStatus::Reviewed
|
||||
} else {
|
||||
before[k]
|
||||
};
|
||||
assert_eq!(*status, expected, "{raw}");
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if op != "remove" {
|
||||
assert!(
|
||||
before.keys().all(|k| after.contains_key(k)),
|
||||
"keys kept: {raw}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn is_below(key: &ElementKey, ancestor: &ElementKey) -> bool {
|
||||
|
||||
@@ -348,3 +348,46 @@ fn no_report_operation_runs_on_a_preview() {
|
||||
let state = canvas(call_with_preview(&preview, "preview.state", "{}"));
|
||||
assert_eq!(state["value"]["status"], json!("published"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_preview_holds_a_bounded_number_of_bounded_drawings() {
|
||||
use faunosteo_core::domain::sheet::preview::MAX_HELD_DRAWINGS;
|
||||
let huge = vec![b' '; 2 * 1024 * 1024 + 1];
|
||||
let sha = faunosteo_core::domain::sheet::verdict::sha256_hex(&huge);
|
||||
let oversized = PreviewDrawing {
|
||||
asset_id: "a".into(),
|
||||
sha256: sha,
|
||||
bytes: huge,
|
||||
};
|
||||
let failure = load_err(
|
||||
input(PreviewStatus::Draft, document_text(), None),
|
||||
vec![oversized],
|
||||
);
|
||||
assert_eq!(
|
||||
(failure.kind(), failure.detail()),
|
||||
("caps", "drawing_bytes".to_owned())
|
||||
);
|
||||
let mut draft = PreviewSheet::load(
|
||||
input(PreviewStatus::Draft, document_text(), None),
|
||||
vec![horse_drawing()],
|
||||
)
|
||||
.unwrap();
|
||||
for i in 1..MAX_HELD_DRAWINGS {
|
||||
let added = PreviewDrawing {
|
||||
asset_id: format!("extra-{i}"),
|
||||
..horse_drawing()
|
||||
};
|
||||
draft.add_drawing(added).unwrap();
|
||||
}
|
||||
let one_more = PreviewDrawing {
|
||||
asset_id: "one-more".into(),
|
||||
..horse_drawing()
|
||||
};
|
||||
assert_eq!(
|
||||
draft.add_drawing(one_more),
|
||||
Err(PreviewFailure::Caps(vec![
|
||||
faunosteo_core::domain::sheet::caps::CapName::Drawings
|
||||
]))
|
||||
);
|
||||
assert_eq!(draft.drawing_reads(), 1, "the same bytes are read once");
|
||||
}
|
||||
@@ -110,7 +110,7 @@ fn a_clean_sheet_passes_bound_to_its_round() {
|
||||
let keys: Vec<&str> = verdict.groups.iter().map(|g| g.key.as_str()).collect();
|
||||
assert_eq!(keys, ["general", "view:main", "zone:z1"]);
|
||||
assert!(
|
||||
verdict.groups.iter().skip(1).all(|g| !g.coverable),
|
||||
verdict.groups[1..].iter().all(|g| !g.coverable),
|
||||
"to_confirm left"
|
||||
);
|
||||
assert!(verdict.changes.is_none());
|
||||
@@ -540,3 +540,45 @@ fn a_document_at_every_cap_is_verified_in_time() {
|
||||
"the core's share of the 120 s budget"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_cap_holds_at_cap_minus_one_and_cap_and_fails_one_over() {
|
||||
use faunosteo_core::domain::sheet::AnatomicalSheetDocument;
|
||||
use faunosteo_core::domain::sheet::caps::caps_report;
|
||||
const MIB: u64 = 1024 * 1024;
|
||||
let typed =
|
||||
|doc: &Value| -> AnatomicalSheetDocument { serde_json::from_value(doc.clone()).unwrap() };
|
||||
let names = |doc: &AnatomicalSheetDocument, sizes: &[u64]| -> Vec<&'static str> {
|
||||
caps_report(doc, 0, sizes)
|
||||
.exceeded
|
||||
.iter()
|
||||
.map(|c| c.as_str())
|
||||
.collect()
|
||||
};
|
||||
let base = typed(&document());
|
||||
for (sizes, expected) in [
|
||||
(vec![1; 3], vec![]),
|
||||
(vec![1; 4], vec![]),
|
||||
(vec![1; 5], vec!["drawings"]),
|
||||
(vec![2 * MIB - 1], vec![]),
|
||||
(vec![2 * MIB], vec![]),
|
||||
(vec![2 * MIB + 1], vec!["drawing_bytes"]),
|
||||
(vec![2 * MIB, 2 * MIB, 2 * MIB - 1], vec![]),
|
||||
(vec![2 * MIB, 2 * MIB, 2 * MIB], vec![]),
|
||||
(
|
||||
vec![2 * MIB, 2 * MIB, 2 * MIB, 1],
|
||||
vec!["drawings_total_bytes"],
|
||||
),
|
||||
] {
|
||||
assert_eq!(names(&base, &sizes), expected, "{sizes:?}");
|
||||
}
|
||||
for (count, expected) in [(63, vec![]), (64, vec![]), (65, vec!["views"])] {
|
||||
let mut doc = document();
|
||||
let extra = (1..count).map(|i| {
|
||||
json!({ "id": format!("d{i}"), "kind": "detail", "name": name("D"), "svg_asset_id": null,
|
||||
"view_box": { "min_x": 0, "min_y": 0, "width": 1, "height": 1 }, "parent_view_id": "main" })
|
||||
});
|
||||
doc["views"].as_array_mut().unwrap().extend(extra);
|
||||
assert_eq!(names(&typed(&doc), &[1]), expected, "{count} views");
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,8 @@ fn the_hostile_corpus_answers_as_the_contract_table() {
|
||||
("script.svg", Rejected, active),
|
||||
("style-element.svg", Rejected, active),
|
||||
("url-unicode-space.svg", Rejected, active),
|
||||
// A processing instruction survives in the bytes the tree never reads.
|
||||
("comments-pi-cdata.svg", Rejected, active),
|
||||
// Hard rejections of the reader.
|
||||
("bom.svg", Rejected, Some("malformed")),
|
||||
("cdata-desync.svg", Rejected, Some("too_deep")),
|
||||
@@ -71,7 +73,6 @@ fn the_hostile_corpus_answers_as_the_contract_table() {
|
||||
("xlink-other-prefix.svg", Cleanable, None),
|
||||
("xlink-prefix-rebound.svg", Cleanable, None),
|
||||
// Nothing removed (comments, stray text and clamped values are no removal).
|
||||
("comments-pi-cdata.svg", Clean, None),
|
||||
("dangling-references.svg", Clean, None),
|
||||
("duplicate-ids.svg", Clean, None),
|
||||
("osteo-halo-id.svg", Clean, None),
|
||||
@@ -134,6 +135,92 @@ fn active_names_are_listed_and_ordinary_removals_are_not() {
|
||||
assert_eq!(read_svg(&text).unwrap_err().reason(), "too_complex");
|
||||
}
|
||||
|
||||
/// The security audit's probes (V1-2.2): content the classification must refuse, never clean.
|
||||
#[test]
|
||||
fn hidden_or_html_content_is_refused_not_cleaned() {
|
||||
let long = "A".repeat(4097);
|
||||
let svg = |body: &str| {
|
||||
format!(
|
||||
"<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:h=\"http://www.w3.org/1999/xhtml\">{body}</svg>"
|
||||
)
|
||||
};
|
||||
let cases = [
|
||||
"<?xml-stylesheet type=\"text/xsl\" href=\"https://attacker.example/x.xsl\"?>".to_owned()
|
||||
+ &svg("<path d=\"M0 0h1\"/>"),
|
||||
svg("<?xml-stylesheet href=\"x.css\"?><path d=\"M0 0h1\"/>"),
|
||||
svg(&format!("<title>{long}<script>alert(1)</script></title>")),
|
||||
svg(&format!("<title onload=\"x()\">{long}</title>")),
|
||||
svg(&format!(
|
||||
"<desc>{long}<foreignObject><iframe src=\"https://e/\"/></foreignObject></desc>"
|
||||
)),
|
||||
svg("<h:img src=\"https://e/x.png\"/>"),
|
||||
svg("<h:meta http-equiv=\"refresh\" content=\"0;url=https://e\"/>"),
|
||||
svg("<h:input type=\"image\" src=\"https://e\"/>"),
|
||||
svg("<h:source srcset=\"https://e/a.png\"/>"),
|
||||
svg("<h:frame src=\"https://e\"/>"),
|
||||
svg("<h:form action=\"https://e\"/>"),
|
||||
svg("<h:div>x</h:div>"),
|
||||
svg("<g><x:thing xmlns:x=\"urn:x\" src=\"https://e\"/></g>"),
|
||||
];
|
||||
for case in cases {
|
||||
let cleaning = clean_svg(case.as_bytes());
|
||||
assert_eq!(
|
||||
outcome(&cleaning),
|
||||
(Rejected, Some("svg_active_content")),
|
||||
"{case}"
|
||||
);
|
||||
assert!(!cleaning.active.is_empty(), "{case}");
|
||||
}
|
||||
// A long title alone is still cleaned; editor metadata stays cleanable.
|
||||
assert_eq!(
|
||||
outcome(&clean_svg(
|
||||
svg(&format!("<title>{long}</title>")).as_bytes()
|
||||
)),
|
||||
(Cleanable, None)
|
||||
);
|
||||
let inkscape = r#"<svg xmlns="http://www.w3.org/2000/svg" xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"><sodipodi:namedview id="n"/><path d="M0 0h1"/></svg>"#;
|
||||
assert_eq!(outcome(&clean_svg(inkscape.as_bytes())), (Cleanable, None));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_verdict_refuses_a_stored_processing_instruction() {
|
||||
use faunosteo_core::domain::sheet::verdict::{
|
||||
DrawingResult, VerdictBinding, VerdictDrawing, VerdictInput, compute_verdict,
|
||||
};
|
||||
let bytes = b"<?xml-stylesheet href=\"https://e/x.xsl\"?><svg xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M0 0h1\"/></svg>";
|
||||
let asset = "11111111-2222-4333-8444-555555555555";
|
||||
let document = serde_json::json!({
|
||||
"schema_version": 2, "species_id": "canine", "name": { "fr": "C", "en": "C" },
|
||||
"description": {}, "scope_disclaimer": {}, "attribution": { "authors": [], "license": null, "notes": null },
|
||||
"vertebral_config": { "regions": [] }, "references": [], "categories": [],
|
||||
"views": [{ "id": "main", "kind": "main", "name": { "fr": "V", "en": "V" }, "svg_asset_id": asset, "view_box": null }],
|
||||
"annotations": [], "finding_zones": []
|
||||
})
|
||||
.to_string();
|
||||
let sha = sha256_hex(bytes);
|
||||
let verdict = compute_verdict(&VerdictInput {
|
||||
binding: VerdictBinding {
|
||||
sheet_id: "s".into(),
|
||||
version_id: "v".into(),
|
||||
revision: 1,
|
||||
review_id: "r".into(),
|
||||
},
|
||||
document: &document,
|
||||
base_document: None,
|
||||
drawings: vec![VerdictDrawing {
|
||||
asset_id: asset,
|
||||
sha256: &sha,
|
||||
byte_size: bytes.len() as u64,
|
||||
bytes: Some(bytes),
|
||||
}],
|
||||
});
|
||||
assert_eq!(verdict.drawings[0].result, DrawingResult::SvgRejected);
|
||||
assert_eq!(
|
||||
verdict.drawings[0].detail.as_deref(),
|
||||
Some("processing_instruction")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_plain_style_sheet_is_cleaned_and_named() {
|
||||
let styled = br#"<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4 4"><defs><style>.st0{fill:#fff}</style></defs><path class="st0" d="M0 0h1"/></svg>"#;
|
||||
|
||||
Reference in new issue
Block a user