Repository navigation
Conversation
An attribute selector whose attribute name contained an ASCII uppercase letter was broken in two ways: * `[ID]` / `a[HREF]` were accepted but silently matched nothing. The attribute matcher lowercases the element's attribute names before comparing but lol-html stored the selector's name as written (`local_name`) instead of `local_name_lower`, so the two sides could never be equal. * `[ID=x]` / `input[TYPE="text"]` threw "Selectors with explicit namespaces are not supported" even though no namespace is present. The `selectors` crate emits `Component::AttributeOther` for any attribute selector whose name is not already ASCII-lowercase, and lol-html mapped every `AttributeOther` to `NamespacedSelector`. The fix, applied as a patch to the vendored lol-html, uses `local_name_lower` for `AttributeInNoNamespaceExists` and accepts and lowers `AttributeOther` when its `namespace` is `None`. Selectors with an actual namespace (`[*|foo]`) are still rejected.
|
Warning Review limit reached
Next review available in: 7 seconds Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
Comment |
There was a problem hiding this comment.
I didn't find any issues with this change — the root-cause analysis is sound, the patch is minimal, and test coverage is thorough. Deferring to a human because this introduces the first vendor patch for lol-html and changes user-facing HTMLRewriter selector semantics (even if only in the correcting direction), which seems worth a maintainer's eyes.
What was reviewed:
- Verified the
patchesfield is an established mechanism inDependency(used by boringssl, libuv, lsquic, etc.) and that the.refstamp hashes patch contents so the re-fetch triggers automatically. - Checked that
AttributeInNoNamespace(with-value, unpatched arm) doesn't need the samelocal_name_lowerfix — theselectorscrate only emits that variant when the name is already lowercase; uppercase-named value selectors go throughAttributeOther, which the patch now handles. - Confirmed the
namespace.is_none()guard in bothparser.rsandast.rsstill lets true namespaced selectors ([*|foo]) fall through toNamespacedSelector, and the new test asserts this.
Extended reasoning...
Overview
This PR fixes two related lol-html bugs that made HTMLRewriter attribute selectors with uppercase names either silently match nothing ([HREF]) or throw a spurious namespace error ([ID=X]). It does so by adding a vendor patch (patches/lolhtml/uppercase-attribute-name-selector.patch) applied via the existing patches mechanism in scripts/build/deps/lolhtml.ts, plus a comprehensive test in test/js/workerd/html-rewriter.test.js.
The patch itself makes two changes to lol-html's selectors_vm: (1) ast.rs now uses local_name_lower for AttributeInNoNamespaceExists and handles the no-namespace AttributeOther case (which the selectors crate emits for uppercase attribute names in value selectors); (2) parser.rs's validate_component accepts AttributeOther when namespace.is_none() instead of unconditionally mapping it to NamespacedSelector. It also extends lol-html's own unit tests with positive and negative cases.
Security risks
None identified. This loosens selector matching only in the direction of CSS/HTML spec compliance (attribute names are ASCII case-insensitive). No untrusted input reaches new code paths that weren't already reachable — the same AttributeComparisonExpr / AttributeExists machinery handles the newly-accepted selectors. Namespaced selectors remain rejected via the guard, and the test explicitly asserts [*|foo] still throws.
Level of scrutiny
Moderate. The Rust changes are mechanical (swap one field, add one match arm mapping to existing expression types), and the test matrix is thorough — existence vs. value selectors, mixed case in both selector and document, :not(), the i flag preserving value case-sensitivity semantics, and the negative namespace case. I checked that the unpatched AttributeInNoNamespace arm doesn't need the same treatment: per the selectors crate's parse_attribute_selector, that variant is only emitted when the name is already lowercase, so local_name there is already correct.
Other factors
I'm deferring rather than approving because this is the first vendor patch on lol-html (establishing a patch relationship the maintainers may want to weigh against upstreaming), and it's a user-visible behavioral change to a Cloudflare-compatible Web API — even though the change is purely corrective and matches browser querySelectorAll behavior, that's the sort of surface a maintainer typically wants to sign off on. The repo's own vendoring guidance asks for an upstream issue link on vendor patches, which isn't present here; that may be worth adding. No bugs were found by the automated bug hunt or my own review.
|
Filed upstream as cloudflare/lol-html#328 and added the link to the patch header. |
There was a problem hiding this comment.
I didn't find any issues, but this introduces the first vendored patch for lol-html and modifies its selector parser/AST logic — worth a human sign-off on the vendoring approach and the upstream-filed fix.
What was reviewed:
- Patch logic:
local_name_lowerswap forAttributeInNoNamespaceExistsand the newAttributeOtherarm gated onnamespace.is_none()— namespaced selectors ([*|foo]) still fall through toNamespacedSelectorin both parser.rs and ast.rs. AttributeInNoNamespace(value + lowercase name) left onlocal_name— correct, since theselectorscrate only emits that variant when the name is already lowercase.patches:wiring inlolhtml.tsmatches the established pattern used by libarchive/lsquic/etc.- New test covers existence/value/mixed-case/
:not()/i-flag and asserts value comparison stays case-sensitive by default.
Extended reasoning...
Overview
This PR fixes two lol-html bugs that made HTMLRewriter attribute selectors with uppercase names either silently match nothing ([HREF]) or throw a bogus namespace error ([ID=X]). It does so by adding patches/lolhtml/uppercase-attribute-name-selector.patch (the first patch for this dep), wiring it into scripts/build/deps/lolhtml.ts via the standard patches: field, and adding a thorough integration test in test/js/workerd/html-rewriter.test.js.
Security risks
None identified. The change makes selector name matching ASCII case-insensitive, which is the HTML spec / browser querySelectorAll behaviour. It does not relax any security check — actual namespaced selectors are still rejected (verified by both a Rust assert_err in the patch and a JS .toThrow() in the test), and attribute value matching remains case-sensitive by default (explicitly tested).
Level of scrutiny
Medium-high. The Rust changes themselves are small and I traced the logic: AttributeInNoNamespaceExists carries both local_name and local_name_lower (the swap is safe); ParsedAttrSelectorOperation has exactly Exists and WithValue (the inner match is exhaustive); and the namespace.is_none() guard correctly distinguishes the uppercase-name case from real namespaced selectors, which parser.rs still rejects before ast.rs ever sees them. The patches: field follows the same pattern as ~10 other deps in scripts/build/deps/.
However, this is the first vendored patch for lol-html, and REVIEW.md flags dependency/vendoring changes as needing situational review. The vendored source is fetched at build time (not checked in), so I couldn't mechanically verify the patch hunks apply cleanly to commit 77127cd2 — CI will catch that, but a maintainer should confirm they're comfortable carrying this patch vs. waiting on the upstream fix (issue is filed and linked in the patch header).
Other factors
Test coverage is strong: the JS test asserts exact match counts (not weak toBeGreaterThan), covers the negative case ([ID=x] → 0 without i), exercises :not(), and confirms [*|foo] still throws. The patch also extends lol-html's own unit tests with the new cases. The PR description clearly explains both root causes with reference to the selectors crate's parse_attribute_selector behaviour. No prior review comments to address.
|
Correction (26 October): parts of this comment are wrong. It said more than I had checked. See #35631 (comment) for what the CI logs show. This is ready for review. Verified green in CI on the lanes that ran (build 80693): The remaining CI red is unrelated infrastructure:
Also verified locally end to end: fresh |
There was a problem hiding this comment.
I didn't find any issues — the root-cause analysis is clear, the patch is minimal, and the test coverage (existence/value/mixed-case/:not()/i flag/namespace-still-rejected) is thorough. Deferring only because this is the first vendor patch carried against lol-html and touches its selector-matching core; worth a quick maintainer glance to confirm you're happy carrying it until upstream lands a fix.
What was reviewed:
ast.rschange:local_name→local_name_lowerforAttributeInNoNamespaceExists, and the newAttributeOtherarm mirrors the existingAttributeInNoNamespacehandling with the lowercased name —AttributeInNoNamespaceitself needs no change since theselectorscrate only emits it for already-lowercase names.parser.rsguard:namespace.is_none()correctly keeps[*|foo]/[svg|href]rejected (covered by both the added lol-html unit tests and the JS test).- Build wiring:
patches:field follows the established convention;.refstamp hashes patches so existing checkouts re-fetch.
Extended reasoning...
Overview
This PR fixes two related bugs in HTMLRewriter's CSS attribute selector matching by patching the vendored lol-html crate. [HREF] was accepted but silently matched nothing (lol-html stored the selector's original-case name while the matcher compares against lowercased element attribute names), and [ID=X] threw a spurious "namespaces are not supported" error (the selectors crate emits Component::AttributeOther for any non-lowercase attribute name even without a namespace, and lol-html rejected all AttributeOther unconditionally).
Three files change: a new patch under patches/lolhtml/ (~50 substantive lines across selectors_vm/ast.rs and selectors_vm/parser.rs plus in-crate unit-test additions), a one-line patches: entry in scripts/build/deps/lolhtml.ts, and a comprehensive new test block in test/js/workerd/html-rewriter.test.js.
Security risks
None. This is CSS selector parsing/matching for HTML rewriting. The change strictly widens which selectors match (uppercase attribute names now work) and does not touch auth, crypto, permissions, or any trust boundary. Namespaced selectors ([*|foo], [svg|href]) are still rejected — verified by both the added lol-html assert_err cases and the JS test's toThrow(/namespaces are not supported/).
Level of scrutiny
Moderate. The logic itself is straightforward — one field swap (local_name → local_name_lower) and one new match arm that lowers AttributeOther { namespace: None } to the same AttributeExists/AttributeComparisonExpr shapes already used by the sibling arms. What raises it above "mechanical" is that it's a patch to a vendored third-party crate's selector VM, and it's the first patch Bun carries against lol-html. Per the repo's vendoring guidance ("Vendor patches stay small with a comment explaining what upstream behavior they correct, plus the upstream issue link"), the PR does everything right: the patch header explains both bugs, cites cloudflare/lol-html#328, and stays minimal. Still, establishing a new patches/lolhtml/ directory and committing to carrying this until upstream fixes it feels like something a maintainer should nod at rather than have auto-approved.
Other factors
- I checked whether
Component::AttributeInNoNamespace(value selector, unchanged in the patch) also needed thelocal_name_lowertreatment — it doesn't, because theselectorscrate only emits that variant when the name is already ASCII-lowercase; uppercase-named value selectors go throughAttributeOther, which the new arm handles. - The
ParsedAttrSelectorOperation::Existsarm inside the newAttributeOtherhandler is likely unreachable in practice (existence selectors go throughAttributeInNoNamespaceExistsregardless of case), but it's required for match exhaustiveness and is harmless. - The
patches:build wiring follows the exact convention used by libarchive/lsquic/libuv/boringssl/etc. The.refstamp issha256(commit + patches)[:16]perscripts/build/deps/README.md, so existing dev checkouts will correctly re-fetch and re-apply. - Test coverage is excellent: existence and value selectors, mixed case in both selector and source document,
:not([ID]), default value case-sensitivity vs. theiflag, prefix operator^=, and the negative case ([*|foo]still throws). The lol-html patch also adds in-crate unit tests for[Data-Foo],[Data-Foo="bar"],[*|foo], and[*|Foo="bar"]. - No bugs were found by the bug-hunting system.
Jarred-Sumner
left a comment
There was a problem hiding this comment.
submit this as a PR to lol-html
|
Submitted upstream as cloudflare/lol-html#332 (fixes cloudflare/lol-html#328). All 178 lol-html lib tests pass on upstream main with the change, and |
|
Closing this PR because it has been inactive for more than 90 days. |
|
This PR stays closed. #43266 now carries this fix and the test from this PR. Where the fix is now
Correction to my comment of 25 JulyThat comment ("Verified green in CI on the lanes that ran") said more than I had checked. When I wrote it, I had read one build log and had seen the name of the test file in the log of one passed shard. Today I read the log of every
No job in that build failed because of this diff. But "green" was wrong: CI ran the new test on 1 of 12 test lanes. |
What
HTMLRewriter attribute selectors now match the attribute name ASCII case-insensitively, matching browser
querySelectorAllbehaviour.Repro
Cause
Two separate lol-html bugs in
selectors_vm:[HREF]silently matches nothing.AttributeMatcher::findlowercases each element attribute name before comparing, so the selector side must be lowercase too.Condition::fromwas storingComponent::AttributeInNoNamespaceExists.local_name(the selector as written) instead oflocal_name_lower, so an uppercase-named selector could never match.[ID=X]throws a bogus namespace error. Theselectorscrate emitsComponent::AttributeOthernot only for namespaced selectors but also for any[Name=value]where the attribute name is not already ASCII-lowercase (parse_attribute_selector:if namespace.is_some() || !local_name_is_ascii_lowercase). lol-html'svalidate_componentmapped everyAttributeOthertoSelectorError::NamespacedSelector.Fix
Applied as a patch to the vendored lol-html (
patches/lolhtml/uppercase-attribute-name-selector.patch):ast.rs: uselocal_name_lowerforAttributeInNoNamespaceExists, and handleAttributeOtherwithnamespace == Noneby lowering it toAttributeExists/AttributeComparisonExprusinglocal_name_lower.parser.rs: acceptAttributeOtherinvalidate_componentwhennamespaceisNone; actual namespaced selectors ([*|foo],[svg|href]) are still rejected.Verification
test/js/workerd/html-rewriter.test.jscovers existence selectors, value selectors, mixed case in selector and document,:not([ID]), default/ivalue case sensitivity, and confirms[*|foo]is still rejected.selector testsblock (70 tests, 0 fail) still passes.selectors_vm::astunit tests pass with the patch applied (new cases added for[Data-Foo],[Data-Foo="bar"],[*|foo],[*|Foo="bar"]).