Skip to content

parser: linkedom folds NBSP, U+2003, U+FEFF and VT in a class value to a space #1567

Closed

Description

@nc9

Found in the independent review of #1535: linkedom folds non-ASCII whitespace in a class value to a plain space, so rules and detectors see two tokens where a browser sees one.

What happens

linkedom's className setter splits on /\s+/ (the JavaScript whitespace set) and rejoins with a space (element.js, lines 112 to 115). In packages/parser the class attribute of an element parsed from class="cover x" (also U+2003, U+FEFF and a vertical tab, literal or as an entity) reads back as cover x. A browser keeps NBSP inside a single token (classList is ["cover x"], one token with an NBSP) and does not split on U+FEFF or VT. A plain tab is folded correctly. A data-k="cover x" attribute keeps the NBSP, so only class is affected.

Effect: any rule that matches classes sees the wrong tokens. In the fake-auth-overlay rule, .x{position:static} after a frame with class="cover x" hides a real cover (the rule thinks the frame has class x; Chrome does not). No rule can fix this; the page must be tokenised as the HTML spec says.

The same gap exists on the release before #1535, so it is not a regression.

Acceptance Criteria

  • The parsed class value of an element keeps NBSP, U+2003, U+FEFF and VT inside a token (HTML splits class tokens only on ASCII whitespace: space, tab, line feed, form feed, carriage return), tested through packages/parser for each character as a literal and as an entity.
  • A class-matching rule test (for example the fake-auth-overlay decoy .x{position:static} against class="cover x") shows the cover is still found.
  • Other parser consumers that split class (list them with a search) use the same ASCII-only split, with a test.
  • Parsing speed on a 10 MiB page with a 20,000-token class attribute is unchanged within noise.

nik

Activity

  1. added
    bug
    size: S
    rules
    on Nov 2, 2026
  2. added theissue type on Nov 2, 2026
  3. nc9 commented on Nov 4, 2026

    @nc9
    ContributorAuthor

    Acceptance check against v0.0.162 (7c31d5b). The class split shipped in v0.0.161: b576fa9, with the residual stated in 50b3a74.

    # Criterion Result Evidence
    1 A parsed class keeps NBSP, U+2003, U+FEFF and VT inside a token, tested through packages/parser as a literal and as an entity PASS packages/parser/src/dom.ts installClassSplit splits on tab, line feed, form feed, carriage return and space only. class-split-1567.test.ts has "as a literal" and "as an entity" cases for each of the four characters, plus "the five ASCII whitespace characters still split" (12 pass).
    2 A class-matching rule test (the fake-auth-overlay decoy .x{position:static} against class="cover x") shows the cover is still found FAIL (gap) Behaviour holds end to end: with the real parser, .c{fixed}.x{position:static} and class="c cover x" still reports the overlay and class="c x" does not (I ran this through detectFakeAuthOverlay). But no committed test does that: the only NBSP case in overlay-css-1409.test.ts ("a class attribute splits on HTML whitespace only") replaces the element's attributes with a stub and so passes without the parser fix.
    3 Other consumers that split class use the same ASCII-only split, with a test FAIL (gap) Still split(/\s+/) on a class value: packages/rules/src/element-path.ts:35, security/form-captcha.ts:329, content/hidden-text.ts:1090, content/text-content.ts:104, integrity/fingerprint.ts:138, integrity/controls.ts:273, parser/src/visible-meta.ts:93, audit-engine/src/cloud-prefetch-run.ts:308 and apps/cli/src/audit/cloud-payloads-blocklist.ts:142. With the real parser, .x and [class~=x] still match a class of cover x (css-select). The changelog states this residual.
    4 Parse speed on a 10 MiB page with a 20,000-token class unchanged within noise PASS No committed measurement; I measured one here: 10.1 MiB page, 20,000-token class, linkedom parse alone 583, 772, 750 and 548, 691, 952 ms against the patched parse 535, 741, 839 and 536, 710, 1,000 ms (two process runs each, three parses each).

    Ticked 1 and 4. Left open for 2 and 3: a test through the real parser for the decoy case, and either the ASCII split in the consumers above (with a test each) or an amended criterion that names the ones left as a residual.

    nik

  4. nc9 commented on Nov 4, 2026

    @nc9
    ContributorAuthor

    Acceptance check against main 0080fc5 (tag v0.0.165). Boxes 1 and 4 stay ticked from the earlier check.

    # Criterion Result Evidence
    2 A class-matching rule test shows the cover is still found PASS packages/rules/tests/class-split-consumers-1567.test.ts "fake-auth-overlay reads a class with a non-ASCII space as one token" (commit 28dfc15, in v0.0.163). It goes through the real parsePage: .c{fixed} .x{position:static} with class="c cover x" still reports the overlay, for NBSP, U+2003, U+FEFF and VT, each as an entity and as a literal, and the control class="c cover x" (plain space) does not. Ran this file and packages/parser/tests/class-split-1567.test.ts on Bun 1.4.3: 25 pass, 0 fail.
    3 Other consumers that split class use the same ASCII-only split, with a test PASS (residual stated) Search: no .split(/\s...) on a class value is left in packages or apps (non-test). Every class splitter uses the shared CLASS_SPLIT = /[ \t\n\f\r]+/ (packages/parser/src/dom.ts:147): the 20 files are the cloud and blocklist selector collectors, visible-meta, the comment classifier, element-path, hidden-text, text-content, fingerprint, controls, form-captcha, cookie-consent, input-zoom, component-occurrence, unrendered-markup and the a11y dialog, button, list, definition-list, heading, main and tabindex rules (commits 28dfc15 and 4305b7c, both in v0.0.163). overlay-style.ts and shared/page-styles.ts use their own ASCII-only sets. Tests: class-split-consumers-1567.test.ts pins the constant, elementSelector, hidden-text and aria-dialog-name against NBSP (a plain space is the control), plus the overlay cases above. The tests cover the constant and three consumers, not each file; the rest I confirmed by reading the code. Known limit, stated in the v0.0.163 CHANGELOG entry: a CSS selector run through the selector engine (.x, [class~=x]) still matches a class across an NBSP. I confirmed it with the parser: class="cover&nbsp;x" is matched by querySelector(".x") and [class~=x]. The v0.0.161 entry also states that an <svg> element's class list is not covered.

    Not verifiable from here: nothing outstanding. The selector-engine residual is outside this issue's criteria as amended by the changelog; file a separate issue if it should be fixed.

    nik

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugrulessize: S

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions