fix(anatomy): prescan closers searched after their opener; ASCII-only href trim; root painting attributes removed (security audit R3)

This commit is contained in:
bchanot committed 2026-10-15 00:25:43 +02:00
1 parent d3d63394dd
commit 157c854ed1
13 files changed
+3231 -21

No files matched your search

+16 -6
View File
@@ -713,7 +713,8 @@ imports it and restyles `data-state` in place as before.
### 9.2 The SVG reader (`read_svg`)
1. Bounds before any parser (`prescan.rs`, a markup state machine: comments,
CDATA, PIs and quoted values skipped by the grammar, no regex): 2 MiB, a
CDATA, PIs and quoted values skipped by the grammar, each closer searched
after its whole opener so `<!-->` cannot hide markup, no regex): 2 MiB, a
leading BOM refused, `<!DOCTYPE`/`<!ENTITY` anywhere, depth 64, 20,000
elements, 256 attributes per element and 100,000 in all, 16 namespace
declarations, 100,000 raw `<` and 200,000 raw `=`. Reason: roxmltree 0.21.1
@@ -751,16 +752,21 @@ imports it and restyles `data-state` in place as before.
- O3 (`oracles/r3/highlight.json`): 36 highlighted compositions (every
observation and view of the three reports, an existing nested `<defs>`, a
detail view with its own asset and no viewBox): tree-equal.
- O4/O5 (`oracles/r3/sanitiser.json`): 36 hostile files
- O4/O5 (`oracles/r3/sanitiser.json`): 41 hostile files
(`tests/fixtures/svg/hostile`) and 10 generated cases: equal to the
TypeScript verdict or a declared one (9.4); the 4 product SVGs (horse
drawing, partner logo, 2 public logos) untouched, tree-equal. Mutation
checks run on the oracle tests (a cap, the namespace rule, the twin floor,
the halo placement): each mutant failed the suite.
- Security audit pass 1: PASS with one MEDIUM in the prescan (a closer
searched from inside its own opener: `<!-->` let crafted markup hide 5,000
nesting levels or 3,000 attributes, then roxmltree overflowed the stack),
fixed with regression cases in cargo and through the shipped wasm; two LOW
(Unicode-spaced `href`, root painting attributes) fixed the same way.
- Shipped wasm (`packages/core-wasm/tests/anatomy.test.ts`): the corpus plus
floods (99,000 nesting levels, 20,001 nodes, 150,000 `<` in a comment, 257
attributes, 2 MiB + 1, a 12 × 20 `<use>` chain, 1.9 MiB of `>`), each in a
fresh instance: a closed outcome, no trap, slowest 24.9 ms, largest linear
fresh instance (49 cases): a closed outcome, no trap, slowest 24.2 ms, largest linear
memory growth 10.1 MiB.
- Runtime: the `SheetHandle` constructor's closed refusal (`<kind>: <detail>`
from a plain `Error`) is `invalid_sheet`; any other throw (RangeError,
@@ -781,8 +787,12 @@ imports it and restyles `data-state` in place as before.
2. Comments and processing instructions are dropped; non-whitespace text is
kept only in `title`/`desc`, each at most 4 KiB (longer: refused whole).
3. The root loses `class` and `style` (an inline SVG lives under the page's
CSS: `class="fixed inset-0 …"` would cover the application); an `id`
outside `[A-Za-z_][\w.:-]*` is removed.
CSS: `class="fixed inset-0 …"` would cover the application) and
`transform`, `filter`, `mask`, `clip-path` (they can paint outside the
canvas box); an `id` outside `[A-Za-z_][\w.:-]*` is removed; an `href` is
local only when it reads `#name` once ASCII whitespace is stripped, as the
URL parser strips it (the TypeScript also trimmed Unicode spaces, so a
no-break space before `#a` passed and resolved as a relative URL).
4. A reference cycle, an expansion over 50,000 elements, and the floods of
9.2 step 1 are refused; the TypeScript accepted them (size counted on the
raw text, refused subtrees included).
@@ -799,7 +809,7 @@ imports it and restyles `data-state` in place as before.
| Measure | Value |
|---|---|
| shipped module | 1,188,740 B raw, **395,771 B gzip -9** (+55.8 KB over R2; budget 600 KB) |
| shipped module | 1,188,573 B raw, **395,701 B gzip -9** (+55.8 KB over R2; budget 600 KB) |
| sheet handle with the drawing read (Node) | 8 to 10 ms |
| `view.canvas` main, first (Node) | 1.2 to 1.4 ms; head warm median 0.85 ms; 143 KiB of SVG |
| Chromium, preview build, CPU × 4, medians of 3 | editor to canvas 503 ms (476 ms before R3); detail open 143 ms (125 ms before R3, runs 109 to 157); browser parse + import of the canvas text 21 ms (22 ms) |