diff --git a/Cargo.lock b/Cargo.lock
index bf03d482..54cd2bf1 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -186,6 +186,7 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
name = "faunosteo-core"
version = "0.1.0"
dependencies = [
+ "roxmltree",
"serde",
"serde_json",
"ts-rs",
@@ -664,6 +665,15 @@ dependencies = [
"libc",
]
+[[package]]
+name = "roxmltree"
+version = "0.21.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f1964b10c76125c36f8afe190065a4bf9a87bf324842c05701330bba9f1cacbb"
+dependencies = [
+ "memchr",
+]
+
[[package]]
name = "rustls"
version = "0.23.46"
diff --git a/Cargo.toml b/Cargo.toml
index 1351812e..edaa88d6 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -24,6 +24,10 @@ serde_json = { version = "1.0.154", features = ["preserve_order", "float_roundtr
ts-rs = { version = "12.0", features = ["serde-compat", "no-serde-warnings"] }
# Zod `.url()` is `new URL()`: the WHATWG parser of the url crate reproduces it (R2 plan P2).
url = "2.5.8"
+# SVG reading (R3): a read-only XML tree, DTD refused by default, node limit; positions give
+# the qualified names the allowlist matches. Its tree building recurses: the core prescan caps
+# the nesting depth before any parse (crates/core/src/anatomy/svg/prescan.rs).
+roxmltree = { version = "=0.21.1", default-features = false, features = ["std", "positions"] }
# The CLI in docker/rust-builder.Dockerfile must be this exact version.
wasm-bindgen = "=0.2.129"
image = { version = "0.25.10", default-features = false, features = ["jpeg", "png", "webp"] }
diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml
index 356bb64b..046b237f 100644
--- a/crates/core/Cargo.toml
+++ b/crates/core/Cargo.toml
@@ -19,6 +19,7 @@ ts = ["dep:ts-rs"]
serde.workspace = true
serde_json.workspace = true
url.workspace = true
+roxmltree.workspace = true
ts-rs = { workspace = true, optional = true }
[lints]
diff --git a/crates/core/tests/fixtures/svg/hostile/osteo-halo-id.svg b/crates/core/tests/fixtures/svg/hostile/osteo-halo-id.svg
new file mode 100644
index 00000000..f7aaa56f
--- /dev/null
+++ b/crates/core/tests/fixtures/svg/hostile/osteo-halo-id.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/crates/core/tests/fixtures/svg/hostile/prefixed-root.svg b/crates/core/tests/fixtures/svg/hostile/prefixed-root.svg
new file mode 100644
index 00000000..5170091a
--- /dev/null
+++ b/crates/core/tests/fixtures/svg/hostile/prefixed-root.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/crates/core/tests/fixtures/svg/hostile/refused-subtrees.svg b/crates/core/tests/fixtures/svg/hostile/refused-subtrees.svg
new file mode 100644
index 00000000..e2b16621
--- /dev/null
+++ b/crates/core/tests/fixtures/svg/hostile/refused-subtrees.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/crates/core/tests/fixtures/svg/hostile/root-without-namespace.svg b/crates/core/tests/fixtures/svg/hostile/root-without-namespace.svg
new file mode 100644
index 00000000..4535713b
--- /dev/null
+++ b/crates/core/tests/fixtures/svg/hostile/root-without-namespace.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/crates/core/tests/fixtures/svg/hostile/std-deviation.svg b/crates/core/tests/fixtures/svg/hostile/std-deviation.svg
index 14511106..fae793ff 100644
--- a/crates/core/tests/fixtures/svg/hostile/std-deviation.svg
+++ b/crates/core/tests/fixtures/svg/hostile/std-deviation.svg
@@ -1 +1 @@
-
\ No newline at end of file
+
\ No newline at end of file
diff --git a/crates/core/tests/fixtures/svg/hostile/whitespace-references.svg b/crates/core/tests/fixtures/svg/hostile/whitespace-references.svg
new file mode 100644
index 00000000..bb8cde86
--- /dev/null
+++ b/crates/core/tests/fixtures/svg/hostile/whitespace-references.svg
@@ -0,0 +1,2 @@
+
\ No newline at end of file
diff --git a/crates/core/tests/fixtures/svg/hostile/xlink-other-prefix.svg b/crates/core/tests/fixtures/svg/hostile/xlink-other-prefix.svg
new file mode 100644
index 00000000..484a2897
--- /dev/null
+++ b/crates/core/tests/fixtures/svg/hostile/xlink-other-prefix.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/crates/core/tests/oracles/r3/sanitiser.json b/crates/core/tests/oracles/r3/sanitiser.json
index f0eb2083..03d66032 100644
--- a/crates/core/tests/oracles/r3/sanitiser.json
+++ b/crates/core/tests/oracles/r3/sanitiser.json
@@ -496,6 +496,80 @@
"not-svg.svg": {
"rejected": "not_svg"
},
+ "osteo-halo-id.svg": {
+ "removed": [],
+ "tree": {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "svg",
+ "attrs": {
+ "xmlns": "http://www.w3.org/2000/svg"
+ },
+ "children": [
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "g",
+ "attrs": {
+ "id": "osteo-halo"
+ },
+ "children": []
+ },
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "path",
+ "attrs": {
+ "d": "M0 0h1"
+ },
+ "children": []
+ }
+ ]
+ }
+ },
+ "prefixed-root.svg": {
+ "rejected": "not_svg"
+ },
+ "refused-subtrees.svg": {
+ "removed": [
+ "metadata",
+ "text"
+ ],
+ "tree": {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "svg",
+ "attrs": {
+ "xmlns": "http://www.w3.org/2000/svg"
+ },
+ "children": [
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "path",
+ "attrs": {
+ "d": "M0 0h1"
+ },
+ "children": []
+ }
+ ]
+ }
+ },
+ "root-without-namespace.svg": {
+ "removed": [],
+ "tree": {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "svg",
+ "attrs": {
+ "xmlns": "http://www.w3.org/2000/svg"
+ },
+ "children": [
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "path",
+ "attrs": {
+ "d": "M0 0h1"
+ },
+ "children": []
+ }
+ ]
+ }
+ },
"script-urls.svg": {
"removed": [
"a",
@@ -589,6 +663,52 @@
"stdDeviation": "2.5"
},
"children": []
+ },
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "feGaussianBlur",
+ "attrs": {
+ "stdDeviation": "0x10 5"
+ },
+ "children": []
+ },
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "feGaussianBlur",
+ "attrs": {
+ "stdDeviation": "100"
+ },
+ "children": []
+ },
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "feGaussianBlur",
+ "attrs": {
+ "stdDeviation": "5 100"
+ },
+ "children": []
+ },
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "feGaussianBlur",
+ "attrs": {
+ "stdDeviation": ""
+ },
+ "children": []
+ },
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "feGaussianBlur",
+ "attrs": {},
+ "children": []
+ },
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "feGaussianBlur",
+ "attrs": {
+ "stdDeviation": "1e-7 100"
+ },
+ "children": []
}
]
}
@@ -718,8 +838,71 @@
]
}
},
+ "whitespace-references.svg": {
+ "removed": [],
+ "tree": {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "svg",
+ "attrs": {
+ "xmlns": "http://www.w3.org/2000/svg"
+ },
+ "children": [
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "title",
+ "attrs": {},
+ "children": [
+ {
+ "text": "a\tb\nc"
+ }
+ ]
+ },
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "path",
+ "attrs": {
+ "class": "a\nb",
+ "d": "M0 0h1",
+ "id": "t\tx"
+ },
+ "children": []
+ }
+ ]
+ }
+ },
"wrong-root-namespace.svg": {
"rejected": "not_svg"
+ },
+ "xlink-other-prefix.svg": {
+ "removed": [
+ "svg@xmlns:x",
+ "linearGradient@x:href"
+ ],
+ "tree": {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "svg",
+ "attrs": {
+ "xmlns": "http://www.w3.org/2000/svg"
+ },
+ "children": [
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "linearGradient",
+ "attrs": {
+ "id": "a"
+ },
+ "children": []
+ },
+ {
+ "ns": "http://www.w3.org/2000/svg",
+ "name": "linearGradient",
+ "attrs": {
+ "id": "b"
+ },
+ "children": []
+ }
+ ]
+ }
}
},
"specs": [