fix(anatomy): V1-2.2 refuse a root visibility that hides the markers

Both composers append the marker layer as the root's last child, so a
root visibility="hidden" whose children set visible back drew the
drawing without a marker (0 marker pixels in Chromium and Firefox, PDF
and canvas). The reader refuses any root visibility but visible
(root_visibility); cleaning, verdict, preview, PDF gate and both
composers answer it.
This commit is contained in:
bchanot committed 2026-10-30 18:56:48 +01:00
1 parent 81f7639c75
commit d8562f60f5
14 files changed
+509 -169

No files matched your search

+12
View File
@@ -13,12 +13,15 @@
//! own and keeps the drawing's ids, so it never holds one the composition writes
//! (`svg::refs::RESERVED_IDS`, the halo filter): the reader refuses such a drawing and both
//! composers refuse such a tree.
//! Both forms append the marker layer as the root's last child, so the root never hides it: a
//! root `visibility` other than `visible` is refused by the reader and by both composers.
use std::collections::HashSet;
use super::layer::{LayerError, find_view, render_layer, view_box_of};
pub use super::svg::refs::HALO_FILTER_ID;
use super::svg::refs::holds_reserved_id;
use super::svg::sanitize::check_root_visibility;
use super::svg::sanitize::{local_reference_text, scope_url_targets, url_targets, urls_are_local};
use super::svg::serialize::is_xml_text;
use super::svg::{Element, Node};
@@ -44,6 +47,9 @@ pub enum ComposeError {
/// composes it. Fail-closed: the reader refuses it (`reserved_id`), so only a tree that did
/// not come out of `read_svg` reaches it, a composed view given back included.
ReservedId,
/// The drawing's root carries a `visibility` other than `visible`, which the marker layer
/// would inherit. Fail-closed: the reader refuses it (`root_visibility`).
RootVisibility,
}
impl From<LayerError> for ComposeError {
@@ -82,6 +88,9 @@ pub fn compose_canvas(
if holds_reserved_id(asset) {
return Err(ComposeError::ReservedId);
}
if check_root_visibility(asset).is_err() {
return Err(ComposeError::RootVisibility);
}
let mut root = Element {
qname: "svg".to_owned(),
namespace: asset.namespace.clone(),
@@ -171,6 +180,9 @@ pub fn compose_highlight(
if holds_reserved_id(&asset) {
return Err(ComposeError::ReservedId);
}
if check_root_visibility(&asset).is_err() {
return Err(ComposeError::RootVisibility);
}
if let Some(view_box) = view_box_of(view) {
asset.set_attr("viewBox", view_box);
}
+7 -3
View File
@@ -6,7 +6,8 @@
//! instruction (`svg_active_content`, the names in `active`, a PI as `?<target>`), or, once
//! no active content is found, a reference to an id the drawing does not define, in the
//! file or after a removal (`dangling_reference`), then an id the composition writes
//! (`reserved_id`, `refs::RESERVED_IDS`); no cleaning is offered;
//! (`reserved_id`, `refs::RESERVED_IDS`), then a root `visibility` other than `visible`
//! (`root_visibility`); no cleaning is offered;
//! - cleanable: only other removals (editor metadata and namespaces, `data-*`, `<style>`,
//! `class` or `style` on the root, ids outside the grammar, unsupported elements, long
//! titles or descriptions): the admin confirms them;
@@ -25,6 +26,7 @@ use ts_rs::TS;
use super::prescan::SVG_CAPS;
use super::refs::{check_reserved_ids, check_targets};
use super::sanitize::check_root_visibility;
use super::serialize::{serialize, stored_form};
use super::{processing_instructions, read_svg, read_svg_for_cleaning};
use crate::domain::sheet::verdict::sha256_hex;
@@ -100,8 +102,10 @@ pub fn clean_svg(bytes: &[u8]) -> SvgCleaning {
if !active.is_empty() {
return rejected(ACTIVE_CONTENT, read.removed, active);
}
if let Err(rejection) = check_targets(&read.root).and_then(|()| check_reserved_ids(&read.root))
{
let checked = check_targets(&read.root)
.and_then(|()| check_reserved_ids(&read.root))
.and_then(|()| check_root_visibility(&read.root));
if let Err(rejection) = checked {
return rejected(rejection.reason(), read.removed, read.active);
}
let preview = serialize(&read.root);
+5 -3
View File
@@ -13,19 +13,21 @@ pub use sanitize::Sanitized;
pub use tree::{Element, Node, SvgRejection};
/// Bounds, parses, sanitises and checks the references of an SVG text: no cycle, within the
/// expansion budget, each naming an id the drawing defines; and no id the composition writes.
/// expansion budget, each naming an id the drawing defines; no id the composition writes and
/// no root `visibility` the marker layer would inherit.
pub fn read_svg(text: &str) -> Result<Sanitized, SvgRejection> {
let root = tree::parse_svg(text)?;
let sanitized = sanitize::sanitize(root)?;
refs::check_references(&sanitized.root)?;
refs::check_targets(&sanitized.root)?;
refs::check_reserved_ids(&sanitized.root)?;
sanitize::check_root_visibility(&sanitized.root)?;
Ok(sanitized)
}
/// `read_svg` as the cleaning reads a file picked for upload: an oversized `title` or `desc`
/// is a removal, not a refusal (`sanitize::sanitize_for_cleaning`); the targets and the
/// reserved ids are checked by the cleaning after it has classified active content
/// is a removal, not a refusal (`sanitize::sanitize_for_cleaning`); the targets, the reserved
/// ids and the root's visibility are checked by the cleaning after it has classified active content
/// (`clean::clean_svg`).
pub fn read_svg_for_cleaning(text: &str) -> Result<Sanitized, SvgRejection> {
let root = tree::parse_svg(text)?;
+19
View File
@@ -434,6 +434,25 @@ fn value_acceptable(qname: &str, value: &str) -> bool {
}
}
/// The root lets the engine's marker layer show: no `visibility`, or `visible` (CSS whitespace
/// and letter case aside). Both composers append the layer as the root's last child, so it
/// inherits the root's `visibility`, which the drawing's own children can set back to
/// `visible`: any other value, `hidden`, `collapse`, a CSS-wide keyword or an unreadable one,
/// is refused (V1-2.2 security review, owner brief 2026-10-30). The root's `style` and `class`
/// are removed by `sanitize`, so this attribute is the one way left to set it.
pub fn check_root_visibility(root: &Element) -> Result<(), SvgRejection> {
let visible = root.attr("visibility").is_none_or(|value| {
value
.trim_matches(is_css_space)
.eq_ignore_ascii_case("visible")
});
if visible {
Ok(())
} else {
Err(SvgRejection::RootVisibility)
}
}
/// CSS whitespace (what the tokenizer skips inside `url(`).
fn is_css_space(c: char) -> bool {
matches!(c, ' ' | '\t' | '\n' | '\r' | '\x0C')
+5
View File
@@ -111,6 +111,10 @@ pub enum SvgRejection {
/// An id the composition writes into the drawing's own document (`refs::RESERVED_IDS`):
/// the drawing's element would stand in for the engine's (V1-2.2, owner brief 2026-10-30).
ReservedId,
/// A `visibility` on the root other than `visible`: the engine's marker layer, appended as
/// the root's last child, inherits it, while the drawing's own children can set `visible`
/// back (V1-2.2 security review, owner brief 2026-10-30).
RootVisibility,
}
impl SvgRejection {
@@ -127,6 +131,7 @@ impl SvgRejection {
Self::ReferenceCycle => "reference_cycle",
Self::DanglingReference => "dangling_reference",
Self::ReservedId => "reserved_id",
Self::RootVisibility => "root_visibility",
}
}
}
+1
View File
@@ -479,6 +479,7 @@ fn canvas_of<'a>(
ComposeError::InvalidCharacter => Failure::new("invalid_character", view_id),
ComposeError::UnscopedReference => Failure::new("svg_rejected", "unscoped_reference"),
ComposeError::ReservedId => Failure::new("svg_rejected", "reserved_id"),
ComposeError::RootVisibility => Failure::new("svg_rejected", "root_visibility"),
})?;
let svg = serialize(&canvas);
if svg.len() > MAX_COMPOSED_BYTES {