Skip to content

fix(integrity): rank a control by the normalised destination, backslash as slash #1495 - #1500

Closed
nc9 wants to merge 3 commits into
mainfrom
fix/integrity-rank-normalised-href-1495
Closed

nc9 wants to merge 3 commits into
mainfrom
fix/integrity-rank-normalised-href-1495

Conversation

@nc9

@nc9 nc9 commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Closes #1495.

shortlist() decides own-site or off-site on urlText(href) (tabs and newlines removed, leading controls stripped), but rank() read the raw href and tested protocol-relative with // only. A destination written with a backslash or split by a tab ranked 1 (local): no long read of its label and no controlsUnread when the label was cut. rank() now takes urlText(href) and treats a backslash as a slash (^(?:scheme:)?[\\/]{2}).

Tests (integrity-evasions-784.test.ts, 39 pass)

  • A sign-in phrase past 400 empty children is found for https://, //, /\, \\, / + tab + /, / + newline + /, a leading space and a leading tab form: fails without the change (checked by running the file against the unchanged source: 1 failure).
  • A plain local destination (/x, x/y, #top) still does not get the long read.

Docs and CHANGELOG updated. Skill change: none.

nik

Review round: differential against the URL parser

looksOffSite(href) (exported) now carries the classification for ranking and for the shortlist's read order: protocol-relative after normalisation (//, \\, /\, \/, tab/newline-split slashes, a leading space or control character), any scheme://, and an http/https/ws/wss/ftp scheme with or without slashes (http:host on an https page is http://host). It leans toward reading. The sign-in path is tested on the normalised text up to 8,192 characters instead of the first 300 of the raw one, so padding the path or the query cannot hide it.

Property tests against new URL(href, "https://example.com/") (about 5,000 generated hrefs: 11 prefixes (empty, space, tab, newline, CR, NUL, 0x01, 0x1f, mixes) x about 60 openers (slash and backslash mixes, tab/newline/space-split, ///, ////, https:/\, http:\\, HTTP://, hTtP://, ws:, ftp:, file:, dot segments /./\, /..//, ?//, #//, percent-encoded %2f, %5c, %09, non-hierarchical schemes) x 7 bodies (host, host with port, userinfo and look-alike hosts, a bare name)):

  • whenever the parser resolves to another host, the text is not "plainly local" (the shortlist keeps it) and looksOffSite is true;
  • whenever the text is "plainly local", the parser resolves it to the page's own host.
    No mismatch was found; the tests fail if the backslash or tab handling is removed. Percent-encoded %2f/%5c are path characters to the parser and are treated as local, as it does.

Round 2 (independent review)

  • Blocker fixed: looksOffSite dropped from the shortlist() bucket line (60,500 off-site decoys no longer fill the 60,000 cap ahead of a real control); rank() still reads off-site first. integrity-budget-1424.test.ts "100,000 tiny controls" passes again; whole budget set run (784, nested, 1424, 1424-decoys, 1465-bounds) plus the new file.
  • Perf: the normalised destination is computed once per control in shortlist() and passed to rank().
  • New integrity-budget-1495.test.ts: bucket order (tab-split sign-in path, 1,000/8,000/9,000-char paths, off-site not promoted), rank() cases, 60,500 decoys before a form button / off-site oauth link / tab-split path / long path, 1 MB tab-padded href. Mutants killed: promote off-site, raw text in shortlist, 300-char read, no cap (shortlist and rank), no AUTH_PATH in rank.
  • Docs: sign-in path read over the first 8,192 characters, off-site links in the second tier.
    Skill change: none.

nc9 added 3 commits November 1, 2026 17:31
…hortlisting, property-tested; sign-in path read to 8,192 characters #1495

Signed-off-by: Nik Cubrilovic <[email protected]>
…ext computed once per control; bounds tests #1495

Signed-off-by: Nik Cubrilovic <[email protected]>
@nc9 nc9 mentioned this pull request Nov 1, 2026
@nc9

nc9 commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.156 as 2c1fa9ce, 48bce75d, 3ecf56b3 via #1506.

nik

@nc9 nc9 closed this Nov 1, 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.

integrity/brand-impersonation: control ranking reads the raw destination, so a backslash or tab-split link skips the long read

1 participant