Skip to content

fix(rules): integrity brand and overlay detectors miss attribute labels, buttons, look-alikes, class geometry #784 - #1399

Closed
nc9 wants to merge 1 commit into
mainfrom
fix/integrity-evasions-784
Closed

nc9 wants to merge 1 commit into
mainfrom
fix/integrity-evasions-784

Conversation

@nc9

@nc9 nc9 commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Closes #784

Security-sensitive: needs an independent review before merge.

What changed

  • Controls: links, <button>, input type=submit|button|image and role=button, label read from text, aria-label, title, value and a logo's alt; a button's destination is its formaction or its form's action. "Continue with Google", "Log in with Google" and the Microsoft pair are in the lexicon.
  • Normalisation: NFKC, accents stripped, a confusables table (Cyrillic, Greek, Armenian, Latin look-alikes and small capitals) on every cue read.
  • Hidden decoy text inside a label is skipped in a second reading; <template> content is read.
  • Identity brokers (Auth0, Okta, Cognito, Supabase, Firebase) and login.windows.net, login.microsoftonline.us, b2clogin.com are not off-brand (suffix match on a label boundary, so auth0.com.evil.invalid still flags).
  • Overlay geometry from !important, inset, and iframe/.class/#id rules in <style> blocks (at-rules skipped, source order, !important wins).

Adversarial pass (review round 1: the automated security review's five classes)

  1. Quadratic scanning in overlay-style.ts (was real). The comment-strip regex /\/\*[\s\S]*?\*\//g rescanned to the end for every unterminated /*, and the rule regex rescanned up to 300 characters from every start. Replaced by one hand-written tokenizer (indexOf only moves forward, the cursor then moves past what it found). Tested on 4 MB of: unterminated comment openers, no braces, a{ openers, nested unclosed @media, closing braces, a:b; runs, a 2 MB selector, !important soup; each is milliseconds. A 1 MB inline style attribute of spaces and bangs, 3,000 iframes against a 4,000-rule sheet, and 10k nested anchors are also linear.
  2. Detection bypass by a cap applied in document order (was real, in two places). MAX_CONTROLS kept the first 3,000 controls, and the CSS reader kept the first 20 blocks / 2,000 rules / 64 KB. Now: every control is listed; text reading is spent in order of relevance (a sign-in attribute, then buttons and links to another host or a sign-in path, then the rest) with a short read for all and full reads for the top ranks, not in document order; CSS is read up to 4 MB, and only rules that can match an iframe on the page are kept, indexed by token, so padding rules, controls or iframes before the real one cannot push it out. Tested: 6,000 padding controls then the real one; 400 long off-site labels burning the full-read budget then a plain one; a wall of 8,000 text links then an attribute-only control; 2.5 MB of junk rules and 4,000 benign iframes before the overlay.
  3. Work bounds that are still bounds. Past the page-wide budget, a control's text is unread and the page past 4 MB of CSS is unread. That is reported, not silent: details.controlsUnread / details.cssTruncated on the check (tested). A page that exceeds a bound without a hit emits no check, because the rules emit nothing when there is no hit (streaming and resident parity); the note is only visible on a hit. Known limit.
  4. Incomplete homoglyph table (widened, still a list). Added accent stripping, small capitals, Armenian and more Cyrillic and Greek letters; mathematical and fullwidth forms were already NFKC-folded. Documented as common look-alikes, not complete.
  5. Evidence leak (was real). The overlay reason printed the iframe's raw src (userinfo, query tokens, fragment, unbounded) and raw id. Now an origin and path only (120 characters), and [\w-] only for the id (tested). The brand reason shows hosts only.
  6. Parser differential (checked, not fixed). The detector reads the linkedom DOM, a browser may differ: nested <a> (the parser nests, a browser auto-closes; reading per control is bounded either way), <noscript> content (scripting on vs off), srcdoc iframes (not scanned), CSS cascade beyond simple selectors, @layer and @container (skipped). Listed as limits, none turned into a verdict.

Tests

integrity-adversarial-784.test.ts (19: perf bounds and the cases above), integrity-evasions-784.test.ts (10), the existing integrity suites, streaming goldens. streaming-page-rules-golden failed once under load (a timeout) and passed 3 times alone. Docs for both rule pages and CHANGELOG updated. Skill change: none.

nik

Review round 2 (independent high-effort review of a7cca92)

  • F1 (HIGH, regression I introduced): normaliser quadratic on combining marks. Marks are now removed BEFORE any NFKC/NFD (every mark is discarded afterwards anyway), so the normaliser never sees a long run; labels are deduplicated before normalising. RuleRunner test: 120 KB of marks in the page text and in a label, milliseconds, real control found.
  • F2 (HIGH): iframes x rules. The last-200 bound is now applied as rules are indexed (a per-key list that drops its oldest), the stylesheet layers are memoised per (id, classes), and selectors are parsed once. RuleRunner test: 5,000 iframe{} rules and 20,000 iframes.
  • F3 (HIGH): starvation, and truncation never reported on a miss. The global short-read budget is gone: every control gets a short read bounded per control (256 nodes visited, 2,000 characters), the most relevant also get a longer read while a page-wide budget lasts. A relevant control whose read was still cut is counted, and with no finding the rules now emit an info brand-impersonation (or fake-auth-overlay for CSS) check with details.scanTruncated. RuleRunner tests: 1.5 MB of node-heavy decoys, 3.5 MB of role=button decoys, a label padded with 20,000 empty elements (note emitted), CSS past 4 MB.
  • F4 (regression): markup in a label. <script>, <style>, <noscript> are not text (as on main); hiding by font-size 0, opacity 0, aria-hidden, hidden, inline or class-based; provider phrases also match with all spaces removed, so Sign<br>in with Goo<i>gle</i> reads.
  • F5: broker allowlist. Narrowed to Google and Microsoft and to the authorize-endpoint shape per host; evil.supabase.co/functions/..., evil.auth0.com/login and Calendly to a broker are flagged again (tests).
  • F6: position caps. Templates (nested too), images and forms have no count caps; form=, aria-labelledby and depth up to 64 (a depth bound) are honoured; tests for the 25th template, a nested template, 500 logos before the control, a button 30 levels inside its form, a logo 30 levels deep.
  • F7a: "Continue with Google" to another IdP or your own domain stays an info single signal (never a failure alone); documented as the trade-off with F5. F7b: inset: 0 counts as a viewport cover only when the iframe has no width and height of its own (test).
  • F8, F9: follow-up issues integrity/fake-auth-overlay: model more of the CSS that styles an overlay iframe #1409 (CSS model) and integrity detectors: complete the confusables table (UTS#39 skeleton) and digit swaps #1410 (confusables), security label, no priority.
  • oxlint -c apps/cli/oxlint.config.mjs on the changed files: only the pre-existing no-object-as-default-parameter in signals.ts remains (it is on main too).

Review round 3 (the automated flags: total work bound, allowlist, and a whole-diff pass)

  • Total work, not per-control caps (flag 1; the per-control cap was the defect). Measured before the fix through the rule runner: 0.9 / 1.9 / 4.7 MB of role=button nested in role=button took 23 s / 100 s / 172 s (every nested control read to its own cap). Now the page as a whole has 400,000 node visits to spend, shared fairly (allowance = what is left / controls still to read, at least 4, at most 256), so neither a flood of decoys nor nesting can starve the real control or multiply the cost; controls with no destination are not read at all; the form and logo lookups are memoised along the path (linear in nodes, whatever the depth); aria-labelledby targets come from one id map built once (it was a lookup per control per root). After: the same shapes take 0.2 / 0.5 / 2.0 s.
  • Hostile RuleRunner tests at 1, 2 and 5 MB (integrity-adversarial-784.test.ts): leaf role=button, buttons in forms, controls with 256 empty children, nested controls, controls under 200 wrappers, form= references, a template per control, aria-labelledby with a template each, nested forms with form= and a template each. At 1 MB and 2 MB: the real control is found, and 2 MB costs under 6x of 1 MB; at 5 MB the nested, forms and template shapes are found within 20 s (measured 2 to 3.3 s). The runner's own 2 s rule budget still abandons a rule on a page this size, reported as a skipped -error check, as for any rule.
  • Allowlist (flag 2): already narrowed in round 2. Only Google and Microsoft sign-in to a broker's authorize endpoint (/authorize, /oauth2/.../v1/authorize, /oauth2/authorize, /auth/v1/authorize, /__/auth/handler) is spared; evil.supabase.co/functions/..., evil.auth0.com/login, evil.okta.com/login/..., evil.firebaseapp.com/..., evil.amazoncognito.com/login and Calendly to a broker are flagged (tests). No host is allowed wholesale.
  • Whole-diff pass (flag 3), what I checked:
    • Regex bounds: every new pattern is linear by construction (alternations of literals, or a delimiter-led repeat that cannot overlap itself); the style attribute is read to 8 KB; HIDDEN_STYLE, SIMPLE_SELECTOR, /!\s*important$/ and the provider patterns were run on megabyte inputs; the CSS scan has no backtracking regex and is exercised on eight hostile shapes.
    • Native calls: normalize() only ever sees mark-free text (the 120 KB marks test).
    • Position caps: none left (templates, images, forms, depth); the only count bounds are on work, and truncation is reported as an info check.
    • Evidence: overlay reasons carry origin and path only, a sanitised id, and a non-http scheme as "(scheme source)"; brand reasons carry URL-parsed hostnames; notes carry counts only.
    • Parser differential (limits, not verdicts): nested <a>, <noscript> with scripting on, srcdoc/about:blank iframes, CSS beyond simple selectors, @layer/@container, escapes (integrity/fake-auth-overlay: model more of the CSS that styles an overlay iframe #1409); look-alikes beyond the table (integrity detectors: complete the confusables table (UTS#39 skeleton) and digit swaps #1410).
    • Denylist completeness: the confusables table and the hidden-text rules are lists; the follow-ups and the docs say so.

Round 2: nested templates are read in place (no clone), aria-labelledby targets are read once and bounded, overlay rules are capped per frame with a page-wide work budget, plain own-site links are not read, the squashed phrase match needs whole-phrase boundaries, and default-budget RuleRunner tests cover each hostile shape. Tenant-owned broker and Google user-content hosts are tracked in #1418.

nik

…work, every cut reported #784

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

nc9 commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

@nc9 nc9 closed this Oct 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(rules): integrity brand and overlay detectors miss attribute labels, buttons, homoglyphs; flag identity brokers

1 participant