Repository navigation
Conversation
… attribute selectors, and the specificity cascade #1409 Signed-off-by: Nik Cubrilovic <[email protected]>
…aps on parts, length, rules and selectors, nested oversize reported #1409 Signed-off-by: Nik Cubrilovic <[email protected]>
…ded and full cascades), open rules end at EOF, nested order, long preludes read, layers undecided #1409 Signed-off-by: Nik Cubrilovic <[email protected]>
… the decided reading; spent nesting budget stops the scan; tests for nested at-rules and long nested children #1409 Signed-off-by: Nik Cubrilovic <[email protected]>
…e decided reading, HTML whitespace, s flag not read, case-insensitive attributes; tests for exact budget exits and selector lowering #1409 Signed-off-by: Nik Cubrilovic <[email protected]>
nc9
added a commit
that referenced
this pull request
Nov 2, 2026
… case-sensitive compare do not cover #1535 Signed-off-by: Nik Cubrilovic <[email protected]>
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.
Fixes #1409, refs #784.
Reproduced on main (v0.0.159) before the change. One iframe that is a fixed full-viewport cover only through its CSS, 23 CSS shapes,
detectFakeAuthOverlay:@media all,@media screen,@layer,@supports,@container, CSS nestingmain iframe,main .c,iframe[id],iframe[id="x"]#id{fixed}then.c{static}(the id wins in a browser)}in a comment, escapes,inset-block/inset-inline.c{static}only,@media print{...}Change (
packages/rules/src/integrity/overlay-style.ts):@media,@supports,@layer,@container,@scope) are read in place in all three readings; a@medialist whose every query is print-only, speech-only ornot allis skipped. Blocks are not searched for their end, so unclosed openers stay linear.&is the parent, no&a descendant); deeper is not read and the CSS is reportedcssTruncated.iframeor*,.class,#id, attribute selectors with all six operators and thei/sflag, pseudo-classes taken as matching. Another tag or a pseudo-element cannot match. The ancestors are not checked, which errs toward detection; no per-element tree walk,closest()or whole-document scan.!important, then specificity (ids, then classes/attributes/pseudo-classes, then tag), then source order. The memo key now includes the frame's values of the attributes some selector tests.hiddenSelectorsis unchanged (it keeps the strict selector reader and does not read at-rules): reading more there would hide real label text.Nesting bounds (follow-up commit, after the automatic security review): a nested rule's selector is read for its last compound only, so a child without
&is itself whatever its parent was, and&is the parent's last compound, never its whole text: nothing multiplies with depth. What remains is capped: 64 parts per list, no produced selector over 2,048 characters (its length is worked out before it is built, so a run of&is not expanded), 50,000 nested rules and 20,000 produced selectors per sheet, depth 8. Whatever a cap drops makes the CSScssTruncated; so does a style rule whose body is past the 256 KB bound and holds nested rules (it was skipped in silence before, because its own selector could not match an iframe). Asserted by counts, not the clock: 20 parts x 10 levels all using&produce 9,360 selectors over 8 levels, 200 x 200 parts produce 4,096, 40 rules of 64 x 64 stop at exactly 20,000, 120,000 nested rules stop at exactly 50,000, a child without&is produced once for 64 parents; 1 MB of&and 1,000&against a 2,000-character parent produce none; 50,000 levels of nesting read 8 rules in 33 ms (iterative, no recursion beyond the bound). Mutants of each cap (rule cap, selector budget, parts cap, length bound, per-parent emission of a child without&, cut flag, nested-body flag, rule-cap and depth reporting) each fail a test; one survivor is equivalent (the nested-rule oversize callback is unreachable, since a nested bound is always inside its parent's).Review follow-up (parity with a headless Chrome matrix of 167 shapes, one push): the first version applied rules it could not evaluate as if they matched, so a decoy that a browser never applies (
@media (max-width:1px){.cover{position:static}},.nothing .cover{...},.cover:hover{...},@layerafter an unlayered cover) hid the real cover: 26 new false negatives against base. Now:@media all|screen|(none)(@supports,@container,@scope,@layer, a media condition, a prelude past 2,048 characters, which is read as undecided with its block still read), and those whose selector has an ancestor part or a pseudo-class (also in nesting, where&is the parent's last compound and a child without&is a descendant)..modal-open .frame{position:fixed...}frames are reported atinfo, an accepted cost) but cannot disable one..c{&{...} position:fixed}readsposition:fixed.<!-- -->is not read; CHANGELOG states the measured cost (up to about 1.9 s) instead of "under a second"; the nested-oversize callback, unreachable since a nested bound lies inside its parent's, is removed.@layer, prelude lengths 2,060, 3,000 and 100,000, nested decoys), decided decoys that still disable (@media screen, an exact selector), enablers, the three readings, open rules in each reading, nested order and the declaration splitter, a dedicated&test. 18 mutants of the new guards (no decided pass, decided keeping undecided at-rules or selectors,hasUnknownnever set, other at-rules known, any media query known, long prelude unread or known, EOF in the token and the plain reading, nested order, nested blocks kept in declarations, attribute case, nested descendant and parent ancestor unmarked, ancestor part and pseudo-class not unknown) each fail a test; the token-reading EOF mutant only died once the test read that reading alone.Hostile timing (
detectFakeAuthOverlay, whole rule, all three readings; the sheet is read up to 4,000,000 characters and reportedcssTruncatedpast that): at 5 MB / 10 MiB: unclosed@media all{openers 351 / 345 ms, balanced@media all{.n{border:0}}blocks 423 / 367 ms, uncloseda{openers 67 / 90 ms, nesting past the depth bound 78 / 87 ms, a selector list of millions of parts 83 / 141 ms, 5 MB+ ofiframe[a="v"]{border:0}rules 554 / 754 ms, 4 KB descendant selectors 98 / 103 ms, unclosed[and:is(234 / 715 ms, escaped at-rule names 506 / 466 ms. With the real overlay rule inside the amount read, it is found in each case that has one. 3,000 frames with distinct attribute values against 2,000 attribute rules: under the 6 s bound.Mutants (each new guard, run separately, each makes at least one test fail): no at-rule descent (17), print filter off (1),
not alloff (1), specificity ignored (3), source order ignored (1, after adding a cross-key equal-specificity case), attribute match always true (3), another tag accepted (2), nesting depth 100 (1), memo key without attributes (1), no universal list (2),¬ replaced (1), pseudo-class counts nothing (1),:where()counted (1), hidden-text scan reading at-rules (1). One survivor, equivalent: accepting a pseudo-element after removing its explicit guard is still rejected by the identifier check that follows.Limits, documented in the rule page and CHANGELOG:
@layerprecedence is not modelled, pseudo-class arguments are not evaluated, attribute values compare case-insensitively (the selector is lower-cased first), nested conditional group rules with bare declarations are not read, an at-rule whose condition may hold ((min-width:1px),@supports not (...)) is read.Tests:
packages/rules/tests/overlay-css-1409.test.ts(87). Passing with the existing integrity-adversarial-784, integrity-evasions-784, integrity-bounds-1423, integrity-budget-784, integrity-budget-1424, integrity, integrity-text-boundary suites; tsgo; docsmake validate; the changelog guard. controls.ts is not touched.Skill: no change needed.
nik