fix(anatomy): V1-2.2 read url() references in their strict spelling only

Security review BLOCK(1): url(#%61) passed the dangling check and the
per-view scoping and resolved in browsers. One strict reading now, other
spellings are active content; glued names are other functions; the
composer refuses an unscoped reference; owner export procedure.
This commit is contained in:
bchanot committed 2026-10-29 16:49:15 +01:00
1 parent 5281337412
commit a678faaa23
13 files changed
+553 -70

No files matched your search

+1 -1
View File
@@ -6,7 +6,7 @@ None is edited by hand.
| File | Tool | How | Expected |
|---|---|---|---|
| `cairo-1.18.4-pycairo-1.27.0-shapes.svg` | cairo 1.18.4 through pycairo 1.27.0 | `generate.sh`: curves, gradient, dash, clip, alpha, text as glyph paths | read with no removal: its colours are written `rgb(20%, 40%, 70%)`, the strict numeric colour function the reader keeps since the owner's decision of 2026-10-29 (before it, the four colours were removed) |
| `cairo-1.18.4-pycairo-1.27.0-shapes.svg` | cairo 1.18.4 through pycairo 1.27.0 | `generate.sh`: curves, gradient, dash, clip, alpha, text as glyph paths | read with no removal: its colours are written `rgb(20%, 40%, 70%)`, the strict numeric colour function the reader keeps since the owner's decision of 2026-10-29 (before it, the five colours were removed) |
| `cairo-1.18.4-pycairo-1.27.0-raster.svg` | same | `generate.sh`: an 8 × 8 image surface painted | refused, `svg_active_content` (an embedded raster `<image>`) |
| `inkscape-1.4.3-inkscape-svg.svg` | Inkscape 1.4.3 (0d15f75042, 2025-12-25) | `generate-inkscape.sh`: `inkscape-source.svg` opened and exported as Inkscape SVG (`--export-type=svg`) | cleanable: `sodipodi:namedview`, the editor namespaces, `sodipodi:docname`, `xmlns:svg` and the `text` element removed and named; shapes, gradient, clip path, references and colours kept |
| `inkscape-1.4.3-plain-svg.svg` | same | `generate-inkscape.sh`: Plain SVG (`--export-plain-svg`) | cleanable: `xmlns:svg` and `text` removed |
+46
View File
@@ -1 +1,47 @@
Owner-supplied editor exports land here (see ../README.md).
# What to export (A6, contract §9.2 and §15)
One small drawing per tool, made in that tool, never retouched by hand afterwards. Same
reference content as `../inkscape-source.svg`, so the results compare:
- an outline with a curve, filled with a two-stop linear gradient, a 2 px dashed stroke;
- an ellipse with a flat colour;
- a rounded rectangle at 50 % opacity;
- the whole group clipped by a rectangle (Illustrator: clipping mask; Figma: a frame with
« Clip content »);
- the word « Garrot » as live text.
Artboard or frame 200 × 150 px. Note the exact version (Illustrator: Aide › À propos
d'Illustrator; Figma: menu › Aide › À propos de Figma, or the desktop app's version).
## Illustrator
1. Fichier › Exporter › Exporter sous… › format SVG (`svg`), « Utiliser les plans de travail »
ticked.
2. Options SVG, two files:
- `illustrator-<version>-export-as.svg`: Style « Attributs de présentation », Police
« Vectoriser », Images « Incorporer », ID d'objet « Noms de calques », Décimales 2, Minifier
off, Responsive on;
- `illustrator-<version>-internal-css.svg`: the same with Style « CSS interne » (the export
most users keep by default; expected cleanable, its `<style>` named as removed).
3. If a third is easy: Fichier › Enregistrer sous… › SVG (`illustrator-<version>-save-as.svg`),
the older dialog, default settings.
## Figma
1. Select the frame, right panel › Exporter › « + » › format SVG.
2. Options, two files:
- `figma-<version>-export.svg`: defaults (« Contours du texte » ticked, « Inclure
l'attribut id » unticked);
- `figma-<version>-ids.svg`: « Inclure l'attribut id » ticked (the layer names become ids).
3. Exporter.
## Then
Copy the files here, unchanged, and tell Claude. The suite
`cargo test -p faunosteo-core --test svg_clean the_owner_editor_exports` reads every `.svg` in
this folder: each must be refused with a closed reason or cleaned into a stored form that reads
back with no removal. A file whose name contains `-active-` must be refused for active content
(useful if you want to try an export with a linked image or an animation). Nothing is uploaded
anywhere: these are test fixtures, committed with the tool and version in their names.
+72
View File
@@ -337,6 +337,78 @@ fn the_vector_tool_exports_are_read_or_refused_for_their_raster() {
assert_eq!(raster.active, ["image"]);
}
/// Security review of the arbitrations (2026-10-29): a `url(` is kept only when its target is
/// `#` and an id in the reference grammar, an optional matching quote and `)`; every spelling
/// a browser would normalise or read otherwise is active content, so the dangling check, the
/// per-view scoping and the expansion budget cannot be walked around. Names glued to `url(` or
/// `rgb(` are other functions, removed.
#[test]
fn every_url_spelling_but_the_strict_one_is_refused() {
let svg = |value: &str| {
format!(
"<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 10 10\">\
<linearGradient id=\"a\"/><path d=\"M0 0\" fill=\"{value}\"/></svg>"
)
};
for value in [
"url(#%61)",
"url(#%66v.main.a)",
"url(\'#\ta\')",
"url(\'#a\tb\')",
"url(#)",
"url(# a)",
"url(\'#a)",
"url(&quot;#a\')",
"url(#é)",
"url(#1a)",
"url(#a b)",
"url(#a rgb(1,2,3))",
"url(#/a)",
"url(#a",
] {
let cleaning = clean_svg(svg(value).as_bytes());
assert_eq!(
outcome(&cleaning),
(Rejected, Some("svg_active_content")),
"{value}"
);
assert_eq!(cleaning.active, ["path@fill"], "{value}");
}
for value in [
"url(#a)",
"URL( \'#a\' )",
"url(&quot;#a&quot;)",
"url(\n#a)",
] {
assert_eq!(
outcome(&clean_svg(svg(value).as_bytes())),
(Clean, None),
"{value}"
);
}
for value in [
"érgb(1,2,3)",
"rgurl(#a(1,2,3)",
"xurl(#a)",
"rgb(1,2,3)rgb(4,5,6)",
"rgb(1,2,3)x",
] {
let cleaning = clean_svg(svg(value).as_bytes());
assert_eq!(outcome(&cleaning), (Cleanable, None), "{value}");
assert_eq!(cleaning.removed, ["path@fill"], "{value}");
}
// The expansion budget holds whatever the spelling: 250 000 references written `%61` are
// refused as active content, as the plain spelling is refused as too complex.
let flood = format!(
"<svg xmlns=\"http://www.w3.org/2000/svg\"><linearGradient id=\"a\"/><path d=\"M0 0\" fill=\"{}\"/></svg>",
"url(#%61) ".repeat(25_000)
);
assert_eq!(
outcome(&clean_svg(flood.as_bytes())).1,
Some("svg_active_content")
);
}
/// Real Inkscape 1.4.3 exports (owner go 2026-10-29; `exports/generate-inkscape.sh`): its
/// editor metadata and namespaces and the `text` it keeps as text are removed and named, so
/// each is cleanable; shapes, gradient, clip path, internal references and colours stay; the
+68
View File
@@ -274,3 +274,71 @@ fn composition_is_deterministic_and_repeatable() {
);
assert_eq!(preview.drawing_reads(), 2);
}
/// Every reference of `text` as a browser reads it, written apart from the core's reader:
/// each `href="…"` and each `url(…)` (any case), quotes and CSS whitespace trimmed, tab and
/// newline removed and `%XX` decoded as the URL parser does. Answers the fragment ids.
fn browser_references(text: &str) -> Vec<String> {
let normalise = |raw: &str| {
let trimmed = raw.trim_matches(|c: char| c.is_ascii_whitespace() || c == '\'' || c == '"');
let cleaned: String = trimmed
.chars()
.filter(|c| !matches!(c, '\t' | '\n' | '\r'))
.collect();
let mut bytes = Vec::new();
let raw = cleaned.as_bytes();
let mut i = 0;
while i < raw.len() {
let hex = raw
.get(i + 1..i + 3)
.and_then(|h| std::str::from_utf8(h).ok());
match (raw[i], hex.and_then(|h| u8::from_str_radix(h, 16).ok())) {
(b'%', Some(byte)) => {
bytes.push(byte);
i += 3;
}
(byte, _) => {
bytes.push(byte);
i += 1;
}
}
}
String::from_utf8_lossy(&bytes).into_owned()
};
let mut out = Vec::new();
for (index, _) in text.match_indices("href=\"") {
let rest = &text[index + 6..];
out.push(normalise(&rest[..rest.find('"').unwrap()]));
}
let lower = text.to_ascii_lowercase();
for (index, _) in lower.match_indices("url(") {
let rest = &text[index + 4..];
out.push(normalise(&rest[..rest.find(')').unwrap_or(rest.len())]));
}
out.into_iter()
.map(|reference| reference.strip_prefix('#').unwrap_or(&reference).to_owned())
.collect()
}
#[test]
fn every_reference_a_browser_reads_stays_in_its_view() {
let preview = preview(&detail_drawing());
for view in ["main", "detail"] {
let text = canvas(&preview, view);
let references = browser_references(&text);
assert!(references.len() >= 2, "{view}");
for reference in references {
assert!(
reference.starts_with(&format!("fv.{view}.")),
"{view}: {reference}"
);
}
}
// The hostile spellings never reach a canvas: the drawing is refused, nothing composed.
for value in ["url(#%66v.main.g)", "url(\'#\tg\')", "url(#%67)"] {
let hostile =
format!("{OPEN}<radialGradient id=\"g\"/><path fill=\"{value}\" d=\"M0 0\"/></svg>");
let refused = canvas_outcome(&self::preview(&hostile), "detail");
assert_eq!(refused["kind"], json!("svg_rejected"), "{value}");
}
}