Repository navigation
fix(html): read a style's CSS comments and escapes before judging it - #309
Merged
Merged
Conversation
A `style` value was judged after its comments were cut out and its backslashes dropped, so a CSS hex escape was never read: `j\61vascript:`, `\6a avascript:` and `\65xpression(` passed the value filter. PR #305's report named the first. The comment cut came before any escape was read as well, so `\/* javascript: */` lost its tail to a "comment" that a stylesheet never opens. `css_text` reads both in one pass, in the order a stylesheet does (CSS Syntax 3, 4.3.2 and 4.3.7): a comment runs to the first `*/` or the end of the value (`/*/` does not close itself), a backslash and one to six hex digits is the code point they name, taken greedily, and a backslash and any other character is that character and never an opener. A code point that is no `char` is dropped and a control character is removed, as `url_ok` already does: both can only make a token easier to see. A left-over backslash is still dropped. SCHEMA_VERSION goes from 1 to 2, because the policy changed (ADR-0012): a description cleaned under 1 may hold a `style` that 2 drops. Nothing re-cleans those rows, as with the rows from before migration 0019. The update model of thrust-core now starts its rows at policy 1 and expects 2 after a description is named, which it could not tell apart from "kept" while both were 1. Tests, in thrust-html/tests/policy.rs: a generated test that writes each character of a dangerous token plain, with a backslash, as a short hex escape closed by any whitespace or by nothing, or as six digits, in either case (the encoder is written from the spec, apart from the decoder); the pinned family of the gap; what the greedy reading makes something else, kept; a token inside a comment, kept; an escaped slash that opens no comment; and escaped harmless values, kept, as the control. Before the change the three tests that cover the gap failed and the controls passed. Refs: #48 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev
temporarily deployed
to
preview-control-plane
November 18, 2026 18:17 — with
GitHub Actions
Inactive
Merged
This was referenced Nov 18, 2026
aRustyDev
added a commit
that referenced
this pull request
Nov 18, 2026
Main moved four commits while #310 was open (#307, #308, #309 and the lettre fix #312), and two files conflicted: - crates/adapters/postgres/src/lib.rs: #308 made `Migration` borrow its strings (`Migration<'a>`), and this branch added migration 0020 to the list. The list is `[Migration<'static>; 20]`: #308's type, this branch's twentieth entry. - docs/src/testing/status.md: #309 rewrote the G-46 row and this branch added G-47 after it. G-46 is main's row, byte for byte (compared with `diff`), and G-47 follows it. Merged, not rebased, because a force-push is blocked on this repository and #310 is already published. The lettre bump of #312 comes in with the merge, which is what turns the `security / deny` job green on this branch (it failed on lettre 0.11.23 alone). Checked on the merged tree before this commit: no conflict markers left, `scripts/check-contract-counts.sh` (74, 6; stage 2: 68, 4), `cargo fmt --all --check`, `cargo clippy --workspace --all-targets -- -D warnings` and the wasm32 clippy of the Worker crates. The test batteries are re-run on the merge commit and listed in the pull request. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
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.
The sanitiser's
stylefilter did not read a CSS hex escape, soj\61vascript:,\6a avascript:and\65xpression(passed it. #305's report named the gap and left it. This reads astylevalue the way a stylesheet does before it is judged. It also fixes a second hole of the same kind, found while writing the tests. #48 stays open: the pages half waits for M3.What changes
css_textreplaces the two steps that came before the token check (cut out the comments, drop the backslashes). It reads the comments and the escapes in one pass, in the order a stylesheet does (CSS Syntax 3, §4.3.2 and §4.3.7):*/, or to the end of the value, and/*/does not close itself;\61vascriptisaandvascript;\76bscriptis U+076B andscript);\/*opens no comment. The old code cut\/* javascript: */out as a comment, so whatever sat in it was never seen. That hole is the second one.stylevalue is removed before the check, asurl_okalready does for URLs. An escape can spell one (java\0 script:), so this rule was needed once escapes were read.SCHEMA_VERSIONgoes from 1 to 2 (ADR-0012), because the policy changed: a description cleaned under 1 may hold astylethat 2 drops. Nothing re-cleans those rows, as with the rows from before 0019;description_schemais what a re-clean would select on.crates/core/html/tests/policy.rs), generated first (AGENTS.md rule 9):prop_a_dangerous_css_token_is_seen_through_any_escape_of_its_characterswrites each character of a dangerous token plain, with a backslash, as a short hex escape closed by any whitespace or by nothing, or as six digits, in either case. Its encoder is written from the spec, apart from the decoder.prop_an_escaped_slash_opens_no_commentandprop_a_token_inside_a_comment_is_not_judged(the second is the control of the first: what a real comment holds is kept).prop_an_escaped_harmless_value_is_kept(\5B57\4F53is a font name, and stays) is the control that none of this passes by dropping every value with a backslash.regression_a_css_hex_escape_cannot_spell_a_dangerous_tokenpins the gap and its family, anda_css_escape_that_spells_something_else_is_keptpins what the greedy reading makes something else.Checked
prop_a_dangerous_style_value_is_dropped); the controls pass. The generated test shrank toexpressio\6e (--in-diff, cargo-mutants 27.1.0)cargo nextest run --workspaceoracle_tests that the profile excludes);thrust-htmlhas 27 testscargo fmt --check; clippy--workspace --all-targets -D warnings,thrust-workerandthrust-edgeon wasm32,thrust-api-v1withopenapi; doctestscheck-deps,check-layout,check-cargo-lock(+ self-test),check-release-plz --first-release required,check-contract-counts(+ self-test),check-migration-lint,check-placementnative-memoryNot shown, and what to decide
tinycss2is the way to get one; say if you want it.charis dropped, where a stylesheet reads U+FFFD, and a left-over backslash is still dropped, sojava\\script:stays blocked though a stylesheet readsjava\script. Both are deliberate: they can only make a token easier to see, never hide one. Blocking more than a browser reads is the safe side of this filter.style="position:fixed..."andid/nameclobbering stay allowed, as in ADR-0141.native-pgandworker-cfcells, the Postgres adapter tests, andscripts/oracle-v1.sh. No storage code changed, and the only values that change arestyles with a backslash, a comment or a control character; CI's cells cover the contract ones.Refs #48
🤖 Generated with Claude Code