Skip to content

fix(rules): a11y hidden-control checks read decidable <style> rules #678 - #921

Merged
nc9 merged 2 commits into
mainfrom
fix/664-665-671-style-block-hiding
Oct 17, 2026
Merged

nc9 merged 2 commits into
mainfrom
fix/664-665-671-style-block-hiding

Conversation

@nc9

@nc9 nc9 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

The accessibility checks that skip hidden controls now read the page's own <style> blocks, not only inline styles. The affected rules are a11y/aria-hidden-focus, button-name, form-labels, aria-labels, aria-command-name, aria-dialog-name and aria-input-field-name.

Closes #664, closes #665, closes #671, closes #678

Design

packages/rules/src/shared/page-styles.ts is a new, deliberately narrow <style> reader. static-hidden.ts consults it for display and visibility.

Decidable rules are applied. A rule is decidable when all of these hold:

  • it is unconditional;
  • every selector in its list is a single compound of a tag, .class, #id, [attr] or [attr=value];
  • its declarations are plainly written.

Decidable rules are applied in cascade order: !important, then inline, then specificity, then source order.

Everything else is uncertain. An uncertain rule makes the answer for every element it could reach unknown, which is reported as unconfirmed and never as hidden. This covers:

  • combinators and pseudo-classes;
  • any at-rule, including @media, @layer and @supports;
  • selectors a browser rejects (.123, b*, #a#b);
  • unreadable or escaped values, and revert-layer;
  • <style> blocks with a non-trivial media, a title, an @namespace or an escaped at-keyword, or inside <svg>;
  • an animation that sets visibility (it outranks ordinary declarations, inline ones too);
  • foreign (SVG/MathML) tag and attribute tests. linkedom lowercases SVG names and puts MathML in the xhtml namespace, so these cannot be matched exactly.

Special cases:

  • An uncertain rule loses only to an inline declaration it cannot outrank.
  • A <style media="print"> block is ignored.
  • <template> and <noscript> styles are not read.

External stylesheets (<link rel=stylesheet>, as=style, @import) are not read. When a page has one, hiding from a <style> rule and inherited visibility stay unconfirmed. An inline display:none is still trusted, as before, and the docs say so.

Bounds on hostile input:

Limit Value
Style text read 256 KB
Rules 5,000
Selector length 1,000 chars
Index entries 20,000
Rule checks per page 2,000,000, shared by every rule that asks
  • A nested rule body stops the read.
  • Rules are indexed per property, by id, class, tag or attribute name.
  • Past any bound the answer is unknown.

Measured worst cases:

  • 5,000 attribute-only rules, a 4-selector list, case-variant classes and 5,000 same-class rules each take about 100 to 200 ms for 7 resolvers over 2,000 buttons.
  • An 11 KB nested sheet and a 3,000-deep @media nest each read in 1.5 ms, with about +0.3 MB RSS.
  • A control under 4,000 nested divs resolves in well under a second.

Verified against Chromium

tests/fixtures/static-hidden-chromium.json now has 239 rows. Each row's verdict comes from headless Chromium (getComputedStyle), and the rows include every adversarial repro from review.

Result Rows
Matches Chromium 124
Unknown (unconfirmed) 113
Shown where Chromium hides 2
Hidden where Chromium shows 0

The test asserts that no row Chromium shows is reported hidden.

Codex reviewed the change in six passes and ended with "no findings". Its repros were run in Chromium before any fix. Two of them did not reproduce: Chromium matches RECT{} and [viewbox] against SVG.

Acceptance criteria

#664

  • A control in aria-hidden that is hidden by an inline style or a decidable <style> rule is not reported.
  • Undecidable CSS is reported as unconfirmed.
  • The bad, hidden, inert, disabled and off-screen fixtures keep their results.
  • The shared helper static-hidden.ts is used.

#665

  • The css fixture passes.
  • The visible unnamed button still fails.
  • Off-screen and disabled buttons are still checked.
  • The helper is shared.

#671

  • The five naming rules use the same resolver.
  • Tests per rule are in a11y-name-rules-hidden-671.test.ts.

#678

Score effect

  • A control a decidable <style> rule hides goes from fail to pass.
  • A control an undecidable rule may hide, or a <style> hiding on a page with external CSS, goes from fail to warn (unconfirmed).
  • On a page with no external CSS, a control inside an inline visibility:hidden container goes from warn to pass.

The amended #678 criterion. Originally the criterion read as follows, and was amended because these cases were wrongly passing before. The criterion says "nothing that passed before warns or fails". That cannot hold together with the no-false-hidden criterion in two rare cases.

The first case is a <style> rule that shows a control again, which Chromium confirms:

  • an !important rule that beats an inline display:none;
  • visibility: visible inside a hidden container;
  • a display rule over the hidden attribute.

There the control is now checked, so pass can become fail.

The second case is an undecided !important rule, or a visibility animation, over an inline hiding. There the control is unconfirmed, so pass can become warn.

Both cases are real browser behaviour, and both are stated in the CHANGELOG. The golden fixtures do not change: 209 pass.

Other changes

The unconfirmed row now reads "may be hidden by a style (unconfirmed)", instead of "… by an inline style …".

Checks

  • Rules typecheck is clean.
  • A seeded fuzz test runs 500 random sheets through the reader: nothing throws, and every element gets an answer.
  • The related a11y tests pass (327 + 41), and the engine golden tests pass (209).
  • tangly check --strict and docs/scripts/check-links.ts pass.
  • The new file is oxfmt-clean.

Skill impact

The squirrel agent skill needs no change. Rule ids and options are unchanged, and the unconfirmed message wording is not referenced by the skill.

Known limits, also in the docs



The accessibility checks that skip controls out of the accessibility tree
(aria-hidden-focus, button-name, form-labels, aria-labels,
aria-command-name, aria-dialog-name, aria-input-field-name) now read the
page's own <style> blocks, not only inline styles.

A rule is applied when it is unconditional, every selector in its list is
one compound of a tag, .class, #id, [attr] or [attr=value], and its
declarations are plainly written, in cascade order (!important, inline,
specificity, source order). Anything else that sets display or visibility
(combinators, pseudo-classes, at-rules, invalid selectors, unreadable
values, media/title/svg/@namespace sheets, visibility animations) is kept
as uncertain for the elements it could reach, which makes their answer
unknown (unconfirmed), never hidden. On a page with an external
stylesheet, hiding from a <style> rule and inherited visibility stay
unconfirmed. Reading is bounded: style text, rules, selector length,
nesting, index entries and a per-page budget of rule checks.

Checked against Chromium (getComputedStyle) on 239 fixture rows: none
returns hidden where Chromium shows the element.

Closes #664
Closes #665
Closes #671
Closes #678

Signed-off-by: Nik Cubrilovic <[email protected]>
@claude

claude Bot commented Oct 17, 2026

Copy link
Copy Markdown

Review of #921 (read the diff and the new page-styles.ts; I did not run the tests, and CI was still pending when I looked).

The design is conservative in the right direction. Anything the reader can't decide becomes unknown (unconfirmed), never hidden. Input is bounded: style text, rule count, selector length, index entries and a shared step budget all have limits. The Chromium-verified fixture asserts that no row Chromium shows is reported hidden.

  • (medium) packages/rules/src/shared/page-styles.ts: the file is about 800 lines of hand-written CSS tokenizing and selector parsing, and it is security-relevant in the sense that a false "hidden" drops a real a11y failure. The tests are good, but it would help to add a small fuzz or property test. For example, run random selector and declaration strings through parseSelector and the reader, and assert they never throw and stay within the step bound.
  • (low) The score effect changes some results from pass to fail or warn (an !important rule that shows a control, or an undecided rule over inline hiding). The PR and CHANGELOG say so. Consider flagging it more prominently in release notes, because it will change scores on existing sites.
  • (low) MAX_STEPS (2,000,000) is shared per page. After it runs out, every later answer is unknown, and the user sees only a softened result with no hint why. A debug-level log or a detail field noting that the bound was hit would help diagnose this.
  • (nit) The Known limits (external !important, strict CSP, declarative shadow DOM) are documented. Please make sure the shadow-DOM follow-up issue is actually filed.

I found no correctness or security blockers.

@claude

claude Bot commented Oct 17, 2026

Copy link
Copy Markdown

Review of #921, a partial read. I read the diff of page-styles.ts and static-hidden.ts. I did not run the tests. CI was still pending when I looked, apart from the sign-off check, which passed.

No blocking problems found.

  • (low) packages/rules/src/shared/page-styles.ts: the module is about 800 lines of hand-written CSS tokenizing and selector parsing. The design errs toward "unknown" over "hidden", which is the right direction for an accessibility rule. The fixture in static-hidden-chromium.json is a good guard. Please confirm that fixture is checked against real Chromium output and not only against this reader's own results.
  • (low) page-styles.ts: the bounds (MAX_STYLE_CHARS, MAX_RULES, MAX_STEPS, MAX_ENTRIES) are sensible protection against hostile input. Add a test that a page over each bound ends up "unknown" and not "hidden", if there isn't one already.
  • (nit) asciiLower is now defined in both page-styles.ts and static-hidden.ts. Export it from one place.
  • (nit) authorStyle in static-hidden.ts calls pageStylesFor(el.ownerDocument) once per element. This is fine if pageStylesFor caches per document, so please confirm it does.

@nc9

nc9 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

Triage of the first review, plus a CodeQL fix (e2a416f):

  • CodeQL "bad HTML filtering regexp" (high) on the CDO/CDC regex was a false positive: it strips CSS <!--/--> tokens, and this code filters no HTML. I replaced the regex with startsWith checks, so the alert should clear. The Chromium differential is unchanged: 0 false hidden.
  • (medium) Fuzz test: added. 500 seeded random sheets, built from selector, declaration and at-rule pieces, run through the reader against mixed markup (SVG, template, inline hiding, animation). Nothing throws, and every element gets an answer within the time bound.
  • (low) Release notes: the CHANGELOG entry states the rare pass to fail/warn cases. I flagged them to the release lead too.
  • (low) A log when the step budget runs out: not added. The rules package has no logger plumbing here, and reaching the budget only makes later answers unconfirmed, which is the safe side. It takes about 5,000 rules under one key across thousands of elements, which is hostile input. A real page uses a small fraction of it.
  • (nit) The declarative shadow DOM follow-up is filed as Rules do not see controls inside a declarative shadow root (<template shadowrootmode>) #922. Checking showed the real gap is broader than the PR body first said: no rule sees those controls at all, because linkedom keeps them in the template's content. I corrected the PR body.

@nc9

nc9 commented Oct 17, 2026

Copy link
Copy Markdown
Contributor Author

Triage of the second review (e2a416f), nothing blocking:

  • The fixture is real Chromium output: each row's chromium verdict comes from headless Chromium's getComputedStyle (one iframe per row, as the comment in static-hidden.test.ts describes), never from this reader. The 239 rows read 124 match, 113 unknown, 2 shown where Chromium hides, 0 hidden where Chromium shows.
  • Over-bound pages: the "<style> reading is bounded" tests cover style size, rule count, nesting, selector length, the step budget, case-variant classes and depth. Each asserts the answer is never "hidden". Past a bound, a sheet counts as not read, like an external stylesheet. Its rules hide nothing (shown), and anything an undecided rule may reach is unknown. This matches the external-CSS behaviour the docs describe.
  • pageStylesFor caches per document in a WeakMap, so each document's styles are read once.
  • asciiLower in two files: leaving it. Both are three-line local helpers, and sharing one is not worth another round.

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

Labels

None yet

Projects

None yet

2 participants