Repository navigation
Conversation
…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]>
This was referenced Nov 2, 2026
nc9
added a commit
that referenced
this pull request
Nov 2, 2026
…255 #1538 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.
Closes #1462.
On v0.0.159 the integrity rules were abandoned ("Not checked") on pages of tens of thousands of multi-attribute controls:
controls.tswalked every attribute of every control with a string allocation per attribute and looked each control's attributes up a second time, with no work budget on either, and thearia-labelledbytarget reads were cached but not charged to the page's visits.What changes (
packages/rules/src/integrity/controls.ts)readControlAttributes: one pass over a control's attributes (up to 4,096; names compared by length before any string work) returnshref,aria-label,title,value,alt,aria-labelledby, the cue flag and how many attributes were looked at. Thehrefand the cues are found wherever they sit in that range (a first version stopped at the 64th: a link or cue past it was counted unread instead of read, which lowered a Calendly kit page from fail to info; padding with 64 junk attributes was the evasion). The listing and prepare steps read it once; the second per-control lookup of 6 attributes is gone. A control with more than 4,096 attributes is counted incontrolsUnread.aria-labelledbyid up to the 4 read) that ordinary pages cannot reach (at most 60,000 prepared controls at 5 units each is 300,000): it is a backstop. A control past it keeps its destination, loses its label attributes and is counted cut. Both are inattributeLimits(mutable, likeintegrityLimits) so tests can lower them.hrefor a missing cue after a cut read is counted incontrolsUnread(and the rule reportsscanTruncated) before the control is dropped.aria-labelledbytarget text is read for at most 300,000 visits in all (three quarters ofTOTAL_VISITS), checked BEFORE each read: a page of thousands of distinct targets cannot spend more, and a control whose target is not read is counted cut. The visits come offTOTAL_VISITSbefore the controls' own reads share what is left. The reviewer's shape (100,000 nested<span id>targets, 25,000 links naming 4 distinct ids each, 4.3 MB) took 37.9 s with the budget off on the previous head; here 1.4 to 2.0 s at the default budget at load about 12 (controlsUnread24,707, the real control found), and one of four runs was abandoned. The budgets bound the work a page can cost, not the time: a rule still runs against a wall-clock budget and a busy machine spends it. Not counted, not new: a cue in a target past its first 300 characters or 256 visits, and a button with no destination (anonclick-only button outside a form).How the budgets were chosen, and what real pages spend
Per unit the listing pass costs about 0.1 to 0.5 microseconds (one control plus its attributes), the prepare pass a few microseconds per control; 2,000,000 listing units is about 0.2 to 0.6 s of work on the densest shapes, and 1,500,000 prepare units about 0.3 s, so a page at the budgets stays well inside the 2 s rule budget. They are about twice what the heaviest shapes the rules read in full need (the 10.4 MB, 40-attribute shape is 1.3M listing units; 4.9 MB of 6-attribute links is 0.55M).
Measured on the 400 largest real HTML pages (0.4 to 6 MB) in a local content store of audited sites (script:
ops/scratch/units-1462.ts, run frompackages/ruleswithbun run; it prints the numbers below): listing units median 2,280, 95th percentile 17,747, maximum 33,041 (1.7% of the budget); prepare units at most 8,728 (0.6% of 1.5M); no page had a control past a budget (controlsUnread0 on all 400). The three heaviest: 2.15 MB, 5,966 controls, 33,041 units; 2.07 MB, 5,966 controls, 33,030 units; 2.26 MB, 5,966 controls, 33,022 units.machine under load 8 to 23, so wall-clock varies; bun 1.4.3, both integrity page rules through RuleRunner at the default 2 s budget, real control last; controls are off-site links unless stated)
aria-labelledbywith 5 idscontrolsUnread173,099<img>in one controlscanControlsalone on the 4.9 MB shape went from about 840 ms to about 400 ms, and on the 10.4 MB 40-attribute shape from about 1,070 ms to about 220 ms, in the same runs. On the 10.4 MB shapes the real control is found, orcontrolsUnreadis reported.Tests
Deterministic, by counts (no wall-clock):
integrity-caps-1462.test.ts(12): the number of controls each cap cuts, exact:MAX_PREPARED(62,000 off-site links and a sign-in path link: 60,000 prepared,controlsUnread2,001, the sign-in link kept),MAX_LABELLEDBY(5 ids: 1, 4 ids: 0), the page's visits (2,000 controls of 241 visits: 1,833 counted; 1,000 of them: 0; 300 controls of 601 visits: 233 counted; a control of about 4,200 visits: 1), the edges (1,600 controls of 250 visits read whole, 1,601 leave 90 counted; 300 controls of 256 visits read whole, of 257 leave 144 counted; the floor of 4 visits with 30,000 controls once the targets' reads are spent),MAX_ALTS_PER_CONTROL, and the distinct targets (10,000 nested targets named by 2,500 links: exactly 1,172 are read and 2,207 controls are counted; 1,000 targets that fit are all read;integrityCounters, a test hook that is off in production).integrity-attribute-budget-1462.test.ts(13):readControlAttributes(the href and cues found at the 64th, 65th, 101st and 4,000th attribute; overlong past 4,096), the listing and prepare budgets by exact counts, a cut read is never a silent skip, the target visits charge, the default budgets pinned.integrity.test.ts(3 added): the Calendly kit page stays fail (brand and obfuscated-script) with the credential link'shrefat the 64th, 65th, 101st and 4,000th attribute; an off-site link labelled by anaria-labelat the 70th attribute is a finding; aninput type=submitvalue and aninput type=imagealt past the 64th attribute in an off-site form are findings.MAX_PREPARED,MAX_LABELLEDBY,TOTAL_VISITS,SHORT_VISITS(255 and 257),MIN_ALLOWANCE(3),LONG_VISITS,LONG_BUDGET_VISITSandMAX_ALTS_PER_CONTROLchanged or made unbounded; the target cache removed; the target budget check removed (the survivor of the previous round), the control not counted when a target is not read, the target-visits charge removed; the listing charge, exhaustion check, prepare charge,covered, the id charge, the overlong cut and both new default budgets; the per-control attribute cap at 64, 4,095 and 4,097; the existing window tests kill the five window caps and the floor. Not distinguishable by any fixture:TOTAL_VISITSby one visit (a cut read costs less than the share, so the share grows back),LONG_BUDGET_VISITSby one (the last read overshoots anyway),MIN_ALLOWANCEraised (more reading, no cut).Through RuleRunner at the default 2 s budget (
integrity-default-budget-1462.test.ts, 18; the old fixture'sruleTimeBudgetMs: 0hid the abandonment): per shape (4.9 MB, 7 MB with 40 attributes, 7 MB with 5 ids, 135,000 labelled links, 330,000<img>) the real control is found orcontrolsUnreadis reported with the budget off; the same shapes at a quarter of the size are not abandoned at the default budget (always run); and the full-size default-budget run is skipped when the machine is busy (loadavgabove half the CPUs), since the budget is wall-clock. With that guard forced off at load 12 to 17 the full-size run passed on this PR, and on v0.0.159 the 330,000-<img>shape was abandoned. The abandonment depends on machine load near the 2 s line, which is why the fix is a per-attribute and per-target charge. The 10 MB shapes are measured above, not tests: they take 0.9 GB to parse.Docs:
docs/rules/integrity/brand-impersonation.mdxstates the attribute pass, both budgets and the target charge. CHANGELOG under Unreleased. Skill change: none.