Skip to content

fix(rules): integrity confusables complete, digit swaps read inside words #1410 - #1541

Closed
nc9 wants to merge 7 commits into
mainfrom
fix/confusables-1410
Closed

nc9 wants to merge 7 commits into
mainfrom
fix/confusables-1410

Conversation

@nc9

@nc9 nc9 commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1410, refs #784.

Reproduced on main (v0.0.159) before the change. A Google or Microsoft sign-in link to an off-brand host, detectBrandImpersonation: not found on main with ϲontinue with Google (U+03F2), sɩgn ɩn wɩth Google (U+0269), sigп іп with Google (Cyrillic п), Sign in with Micгosoft (Cyrillic г), Si⠀gn in with Goo⠀gle (braille blank U+2800 spliced in), and S1gn 1n w1th G00gle, L0g1n w1th Google, C0nt1nue w1th Google, Sign 1n with Google. The three tests for them fail on main; the ordinary-number and other-language tests pass there (they are the baseline).

Change (new packages/rules/src/integrity/confusables.ts; controls.ts loses the table and its two helper constants and gains an import and one changed line in scanControls, so it rebases cleanly under #1462):

  • The table moved to confusables.ts with ϲ and ς (NFKC turns U+03F2 into the final sigma U+03C2, so both are mapped), ɩ, п, г added; U+2800 joins the invisible characters.
  • digitForms(text): in a word ([\p{L}\p{N}]+) that has a letter and one of 0 1 3 5, 0 is o, 3 is e, 5 is s, and 1 is i or l, whichever makes a word of the cue (the word list is derived from the auth phrases and the brand lexicons and action cues): s1gn is sign, g00g1e is google, 1og1n is login; a cue word of the token's length is compared letter by letter, each 1 standing for i or l; no cue word either way reads with i. A number on its own (1995, 10, 5) and a word with only other digits (24h) are untouched. Applied to each label form in scanControls; the page-text haystack is unchanged.
  • The table stays a hand list; the PR states why instead of generating it from UTS fix(security): harden untrusted CLI inputs #39: the cues are ASCII words, so only characters that can stand for one of their letters matter, the full skeleton is about six thousand entries mostly for scripts no cue contains, and an unlisted look-alike stays a way past the match (the rule page says so).

Not firing (tests): prices, years, versions, H1, 24h, Sign 5 times on a page; Russian, Spanish and German sign-in labels (Войти через Google, Iniciar sesión con Google, Mit Google anmelden, ...), to an off-brand host and to Google itself.

Rebased on #1538 (9cb20e5, the work budget): this branch now carries #1538's commits below its own; the CHANGELOG and the rule page paragraph conflicts are resolved.

Review round (the first version folded only the folded reading and the fold was unbounded):

  • digitForms returns the text as written first and the fold when it differs, so a cue with a digit in it matches: Office365 login, Office365 Login and Microsoft Office365 Login to an off-brand host are Microsoft (the first version read office365 as officee6s and lost them).
  • The fold is bounded, not "by the control reader" (a single text node is not cut by it): a label is folded to its first 16,000 characters, the page folds at most 2,000,000 characters (attributeLimits.fold, in the same object as fix(rules): integrity controls: attributes read once and charged to a work budget; aria-labelledby target reads charged to the visits #1462 #1538's budgets) across labels and attributes, and a control whose label or attribute was not folded in full is counted in controlsUnread. A single 10 MiB text node of 1a1b1c1d tokens, and a page of such links, no longer skip brand-impersonation and fake-auth-overlay at the default budget (on the first version, one 10 MiB link took 4,012 ms against 195 ms on base and both rules were skipped; 20,000 links of 360 characters: 4.8 s then, 0.55 to 0.78 s now with the budget off).
  • The token fold no longer builds the sixteen candidate spellings of a 1-heavy word: a cue word of the token's length is compared letter by letter with each 1 standing for i or l (about 5 times faster).
  • The pool can be spent on purpose, so each control keeps a small allowance outside it (the finding of the delta review: 125 invisible aria-label or title fillers of 16,000 characters of 1a1b1c1d spent the 2,000,000-character pool, and a swapped cue in a text or an attribute after them was missed; the plain reading was never affected): the first 300 characters of a control's attributes and the first 300 of its text fold outside the pool, and the pool is charged only for what is past them (the whole text when both cover it, else only the control's own allowance folds). A short swapped-digit label folds whatever the pool holds, before or after the fillers; the label as written is always read; a control not folded in full is counted unread. Cost: the allowance is bounded by page bytes (a 12.5 MB page of 20,000 links with 300 characters of digit-heavy attribute and text each ran 1.1 s with the budget off); a page of 60,000 such controls, 37 MB, is past the 10 MiB cap.
  • A swapped-digit cue in an attribute's later windows is read: both readings of an attribute are windowed.
  • The capital lunate sigma (U+03F9) is a c: it is mapped before NFKC (which would make it a sigma); U+03F2 is covered by the NFKC path and tested through readable.
  • Limits, in the docs: a glued token that needs both an i and an l (signinwithg00g1e) is read with i and is not a cue, and page text is not digit-folded, only the text and attributes of controls.

Mutants (each separately, restored from a clean copy after each): the allowance round adds the exact-fit comparison, the allowance consumption, its size (0, 299, 301), the plain reading dropped in the exhausted text and attribute paths, the partial head fold, the pool charge and both cut counts, each failing a test; this round's earlier set (the 23-mutant set of the first version targeted code this round rewrote, so it was rebuilt): the as-written reading dropped, the fold applied without the guard (equivalent), 1 read only as i or only as l, the fallback as l, 5 not folded, the digit guard without 0, the label bound at 15,999 and 16,001, the cut not counted, the budget check, its cut count and its charge removed, a label folded past 16,000, the attribute fold charge removed or always on, an exhausted attribute not counted, the lunate sigma pre-fold removed or only one of its two code points, and the budget unbounded each fail a test. Equivalent survivors: the early return for a token without a 1, and U+03F2 in the pre-fold (NFKC and the table already map it).

Docs: the label normalisation sentence of docs/rules/integrity/brand-impersonation.mdx; CHANGELOG entry.

Tests: packages/rules/tests/confusables-1410.test.ts (18) and integrity-fold-budget-1410.test.ts (17: bounds by counts, the allowance and the pool, and the rules at the default budget, a quarter size always and full size when the machine is quiet). Passing, each file on its own: integrity, integrity-text-boundary, integrity-budget-1424, integrity-budget-784, integrity-bounds-1423, integrity-budget-1495, integrity-unread-once-1491, integrity-evasions-784 and integrity-adversarial-784 (one linearity-ratio test failed once under a load average of 17 and passed 3 of 3 alone); tsgo; docs make validate; the changelog guard.

Skill: no change needed.

nik

nc9 added 6 commits November 2, 2026 16:34
…ge work budget; aria-labelledby target reads charged to the visits #1462

Signed-off-by: Nik Cubrilovic <[email protected]>
…ds counted; default-budget shapes also at a quarter size #1462

Signed-off-by: Nik Cubrilovic <[email protected]>
…ounted unread, not skipped as having no destination or cue #1462

Signed-off-by: Nik Cubrilovic <[email protected]>
…p 4,096), distinct aria-labelledby targets metered before reading, edges pinned, test hook off in production #1462

Signed-off-by: Nik Cubrilovic <[email protected]>
…269, pe, ghe, braille blank) and reads digit swaps inside words #1410

Signed-off-by: Nik Cubrilovic <[email protected]>
…nded by length and page budget, attribute windows folded, capital lunate sigma #1410

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9
nc9 force-pushed the fix/confusables-1410 branch from 1ac774f to 3a20f69 Compare November 2, 2026 09:56
…aracters outside the page pool; exhaustion keeps the plain reading; boundaries pinned #1410

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9 nc9 mentioned this pull request Nov 2, 2026
nc9 added a commit that referenced this pull request Nov 2, 2026
…guarantee, the pool limit and the measured cost #1541

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

nc9 commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

Shipped in v0.0.160. The commits were cherry-picked onto the release branch and rebase-merged: cf70c35 629d494 73c9daa e6b0d6b c6e23ee 8d54f8a 563fe21.

Closing this PR since the change is on main.

nik

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.

integrity detectors: complete the confusables table (UTS#39 skeleton) and digit swaps

1 participant