Skip to content

refactor(html): move the sanitiser into crates/core/html - #300

Merged
aRustyDev merged 1 commit into
mainfrom
chore/48-html-crate
Nov 18, 2026
Merged

aRustyDev merged 1 commit into
mainfrom
chore/48-html-crate

Conversation

@aRustyDev

Copy link
Copy Markdown
Owner

Part 1 of 3 for #48 (the work-item half). This one moves code and changes no behaviour; the hardened default is PR 2, and storing description_stripped through the use-cases is PR 3.

Why

#48 wants one sanitise path for compat and /api/v1, in the use-case layer. crates/core may not depend on thrust-editor-doc: scripts/check-layout.sh rule 4 refuses any normal or build dependency from core/ on a crate outside it. So the sanitiser has to live inside core/ before the use-cases can call it.

What changes

  • New crate thrust-html at crates/core/html/, depending on ammonia = "4.2.5" only. The floor is the release that patches RUSTSEC-2026-0533 (the lockfile moved there in fix(deps): bump ammonia to 4.2.5 for RUSTSEC-2026-0533 #147; the manifest still allowed 4, so a fresh resolve could have picked 4.0.0, which D-019 rules out).
  • git mv of sanitize.rs to crates/core/html/src/lib.rs, so history follows the file.
  • thrust_editor_doc::sanitize still resolves: it is now pub use thrust_html as sanitize, behind the same sanitize feature.
  • thrust-compat-plane and thrust-api-v1 depend on thrust-html directly. They used nothing else of thrust-editor-doc, and the three call sites change by their path only.
  • The file now obeys the workspace panic lints ([lints] workspace = true, like thrust-ports and thrust-core). Nine sites indexed or unwrapped (strip_once, tag_end, url_ok, validate_binary_data); they are now get, first, is_some_and and bytes().enumerate(), with the same results on every input that was reachable.
  • Two tests move with the code (validate_html_content_semantics, unsanitised_payload_is_caught) because they need no editor schema. The tests that parse with the schema or compare with nh3 stay in thrust-editor-doc.
  • Wiring: workspace member and dependency, release-plz.toml (member entry, changelog_include, the first-release tag pattern the deps job requires for a crate not in v0.2.0), CLEAN_CRATES in check-deps.sh, the core/ and editor/ READMEs, crates.md, features.md, and the probes/ammonia-400 include path.

Checked

Check Result
examples/sanitize_check over the 431 corpus inputs (the 169 entries of the XSS corpus plus the editor documents), before and after, all three forms (clean, stripped, hardened) byte-identical (cmp)
The same comparison with the closing-tag test of strip_once mutated (</p> no longer read as a tag) differs at byte 1291, so the comparison can see this kind of change
cargo nextest run on thrust-html, thrust-editor-doc, thrust-compat-plane, thrust-api-v1 1646 passed, 4 skipped (the oracle_ tests); both moved tests ran in thrust-html, and allow_list_preservation_of_editor_html still runs in thrust-editor-doc
cargo clippy with -D warnings: workspace (every target), thrust-worker and thrust-edge on wasm32, thrust-api-v1 with openapi; each with --locked as lint.yml has it all four exit 0
cargo fmt --all --check, cargo deny --locked check clean; advisories, bans, licenses, sources ok
check-deps.sh exit 0, thrust-html in CLEAN_CRATES, no forbidden crate
check-layout.sh and --self-test ok, 23 crates; 23 of 23 cases
check-cargo-lock.sh and --self-test ok, 492 packages; 10 of 10
check-release-plz.py --first-release required ok against v0.2.0
check-plane-500.sh, cargo test --doc on the four crates ok; no doctests exist in them

Not shown

  • CI has not run. The contract suite, the oracle-v1 gate, the pg-adapter tests and the mutants job are not run locally for this PR; it changes the path of three calls, not what they do.
  • oracle_v1_write_with_sanitiser_matches_python_plus_js was not run (it needs the generated spike-0006 output); PR 2 pins plane_builder() in it.
  • No mutation run: thrust-html's own tests are two, and the real coverage of strip_tags and the filters is what PR 2 adds (a generated test and the nine-class test). A run now would only measure what is missing.
  • The deps job steps that read nothing I changed (topology, edge config, placement, migration lint, flagship, workflow lint, actionlint, OpenAPI diff) were not run locally.

Left alone

  • clippy prints cargo manifest warnings that were there before (missing [lints] in other crates; base64 is unused by thrust-editor-doc's library, as it was before, since the moved file never used it).
  • docs/src/testing/status.md's inventory is a dated snapshot (it says 12 default-profile tests; the run is 1646), so I did not touch it. PR 2 adds its entries.

Refs #48

🤖 Generated with Claude Code

The use-cases have to clean a work item's description (issue #48: one path for compat and v1), and
scripts/check-layout.sh rule 4 forbids crates/core from depending on thrust-editor-doc. So the sanitiser
becomes its own crate inside core/: thrust-html, on ammonia only (floor 4.2.5, the RUSTSEC-2026-0533 fix
and the 4.1+ D-019 needs). No behaviour change.

- git mv crates/editor/doc/src/sanitize.rs crates/core/html/src/lib.rs, so history follows the file.
- thrust-editor-doc keeps `thrust_editor_doc::sanitize` as a re-export behind its `sanitize` feature.
- thrust-compat-plane and thrust-api-v1 depend on thrust-html directly; they used nothing else of
  thrust-editor-doc.
- The file opts into the workspace panic lints, as the other core crates do: the indexing and the one
  unwrap in strip_once, tag_end, url_ok and validate_binary_data become get/first/bytes().enumerate().
- The two tests that need no editor schema move with the code; the ones that parse with it, or compare
  with nh3, stay in thrust-editor-doc.
- Wiring: workspace member and dependency, release-plz (member entry, changelog_include, first-release
  tag pattern), check-deps CLEAN_CRATES, core and editor READMEs, crates.md, features.md, and the
  ammonia-400 probe's include path.

Shown unchanged: examples/sanitize_check over the 431 corpus inputs writes byte-identical output (clean,
stripped and hardened) before and after; with the closing-tag test of strip_once mutated, the same
comparison differs at byte 1291.

Refs: #48
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

This branch was previously deployed

1 inactive deployment
preview-control-plane — ec8caddf Deployed Nov 18, 2026 by aRustyDev via reconcile #74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant