Repository navigation
feat(html): make the hardened sanitiser the default, keeping the editor's embed and rel - #302
Merged
Merged
Conversation
…or's embed and rel Work-item descriptions are cleaned with Thrust's own allow-list now (issue #48; D-016 to D-019), not Plane's. `thrust_builder()` is `hardened_builder()` plus what Plane's list would strip from the editor's own output: - `issue-embed-component` and its four attributes (D-017; `id` is already generic); - `a rel` as the editor writes it (D-018), which means turning off ammonia's own `link_rel` (it refuses to run with both). A `rel` with any token but noopener, noreferrer and nofollow is dropped, so a stored `rel="opener"` cannot give a `target="_blank"` link back its `window.opener` (added here; recorded in D-018). `Sanitizer::default()` and `validate_html_content` use it, so `/api/v1` and Plane's internal routes both do. `plane_builder()` stays, exact nh3 parity, and `Sanitizer::new` lets a comparison with nh3 ask for it: the nh3 oracle test, the sanitize_check example and the ammonia-4.0.0 probe now do. `SCHEMA_VERSION` (1) is added for the stored description to name its policy (used by the next change). Tests (a static example is used only where the research names it, rule 9 (b)): - thrust-html: the nine payloads that Plane's list lets through, read by id from the committed XSS corpus, are neutralised by the default and not by plane_builder(); generated tests of the value rules with a harmless-value control; the embed and link markup kept; the size limits to the byte. - thrust-editor-doc: the default changes none of the 196 editor-generated documents; plane_builder() changes 66 for the two named reasons (5 embeds, 61 rels); the hardened builder changes none; a generated test over rendered documents. The research and the issue say 195 and 129: the corpus is byte-identical to the spike's and has 196 and 130, so the tests assert the corpus's own and DEVIATIONS says so. - contract suite: two tests send the nine through create and update on compat and on /api/v1 and read each back neutralised (the main pass is 73, stage2's 67). - compat parity: X01 records the pin adding rel="noopener noreferrer"; a D-018 projection removes exactly that, refuses a recording that sends a rel of its own, and has three controls. Controls shown failing, with the default pointed back at plane_builder(): 6 of 11 thrust-html tests, 2 of 4 thrust-editor-doc tests, exactly the two new contract tests (71 others pass), and X01 with the projection off. Mutation testing of the sanitiser: every mutant of the policy code is caught; the 77 missed are all in the strip_tags port, which the next change wires in and tests against recorded Django output. Measured and not fixed here: a CSS hex escape (`j\61vascript:`) passes the style filter. The comment that claimed otherwise now says so; it is in G-46. Refs: #48 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev
temporarily deployed
to
preview-control-plane
November 18, 2026 05:39 — with
GitHub Actions
Inactive
Merged
This was referenced Nov 18, 2026
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 2 of 3 for #48 (the work-item half). It follows #300, which moved the sanitiser into
crates/core/htmland is merged. This one changes what the sanitiser does: the default policy is now the hardened one, and it keeps what the editor writes. Part 3 storesdescription_strippedand a schema version through the use-cases.What changes
thrust_builder()ishardened_builder()plus what Plane's allow-list strips from the editor's own output:issue-embed-componentwith its four attributes (idis already generic; D-017), anda relas the editor writes it (D-018). ammonia refuses to run with bothrelallowed and its ownlink_rel, solink_rel(None)goes with it.Sanitizer::default()andvalidate_html_contentuse it, once built (LazyLock), so/api/v1and Plane's internal routes both do.plane_builder()stays as exact nh3 parity, and the newSanitizer::newlets a comparison with nh3 ask for it: the nh3 oracle test, thesanitize_checkexample and the ammonia-4.0.0 probe now do.SCHEMA_VERSION= 1, which part 3 stores with a description.rel="noopener noreferrer"to a link; Thrust now leaves a link as it was sent. A D-018 projection intests/common/mod.rsremoves exactly that string from<a>tags of recorded responses, refuses a recording that sends arelof its own, and has three controls. The fixture is not edited.DEVIATIONS.mdD-016 to D-019 name the code that is there now and the tests that pin each (the register's header asks for one);status.mdG-46.For you to decide or know
relwith any token butnoopener,noreferrerandnofollowis dropped. D-018 as written says "preserved as the editor writes it". Preserving anyrelwould let a storedrel="opener"give atarget="_blank"link back thewindow.openerthat browsers take from it by default. The editor never writes such a value (0 of 196 documents change), so this costs nothing, and it is one function (rel_ok) and one line in D-018. It is mine, not yours: say so if you would rather have the literal reading.research/0008§7 say 195, with 129 unchanged under Plane's list. The corpus is byte-identical to the one the spike measured and the selection rule is unchanged. The 66 documents that Plane's list changes, and the two causes (5 embeds, 61rels), agree exactly; only the total is one short, so 130 are unchanged. The tests assert the corpus's own figures and D-016 to D-018 say 196. I did not chase which document the research left out.j\61vascript:and\6a avascript:are kept (a plain backslash,java\script:, is caught). The comment incss_is_dangerousclaimedj\61vascript:was handled; it now says what the code does. This is the class of the nine payloads (legacy browsers,[inferred]not exploitable in evergreen ones), and D-016's claim is the corpus's 125 of 125, so I did not widen this PR. Decoding the escapes would be about twenty lines and a generated test. Say if you want it.Checked
research/0008§7, through create and update, on compat and on/api/v1(contract suite,native-memory, the main pass, which holds them)plane_builder()thrust-htmltests fail, and 2 of the 4 sanitiser tests ofthrust-editor-doc(the 196-document test fails with "changes 66 of 196" and the generated test fails too)description_html: recorded<a rel="noopener noreferrer">l</a>, answered<a>l</a>plane_builder()changes 66 (5 + 61); the hardened builder changes nonecargo nextest run --workspaceoracle_tests the profile excludes)crates/core/html/src/lib.rs(cargo-mutants 27.1.0)strip_tagsport, which no hermetic test exercises (evenstrip_tags -> String::new()survives). Part 3 puts it to use and tests it against recorded Django outputoracle-v1.sh native-memory controlsVERDICT: PASS, gate, corpus comparison, self-test and controls all 0cargo clippy -D warnings --locked: workspace,thrust-workerandthrust-edgeon wasm32,thrust-api-v1withopenapicargo fmt --check,cargo deny --locked check, doctestscheck-deps,check-layout(+ self-test),check-cargo-lock(+ self-test),check-release-plz --first-release required,check-plane-500,check-contract-counts(+ self-test),check-migration-lint, run again on the tree rebased ontomainNot shown
native-pgandworker-cfcells of the contract suite, and the browser journeys, are CI's; nothing here touches Postgres or the Worker's bindings.oracle_v1_write_with_sanitiser_matches_python_plus_js, now pinned toplane_builder()because nh3 is its oracle, was not re-run: it needs the generated spike-0006 output.style="position:fixed…"andid/nameclobbering stay allowed, as in ADR-0141.crates/spikes/editor-worker) now measures Thrust's policy on/html-to-alland/deep; its CPU numbers inresearch/0008§9 were Plane's. A comment says so; nothing re-measured.Refs #48
🤖 Generated with Claude Code