Skip to content

fix(audit-engine): fan-out signature covers html/body attrs and icon links (#614) - #621

Merged
nc9 merged 9 commits into
mainfrom
fix/template-key-614
Oct 11, 2026
Merged

nc9 merged 9 commits into
mainfrom
fix/template-key-614

Conversation

@nc9

@nc9 nc9 commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Closes #614

Three template rules read inputs the fan-out grouping key did not cover: a11y/html-xml-lang-mismatch (lang, xml:lang on <html>), a11y/aria-hidden-body (aria-hidden on <html> and <body>) and core/favicon (rel and href of icon links). Two pages with the same chrome key but different values there shared a verdict. fanoutInputSignature now includes them (icon links as JSON [rel, href] pairs in document order, because the rule lists formats in the order it finds them).

Rebased onto main (the CHANGELOG entry moved to [Unreleased]), then the open criteria finished.

Criteria

  • Counterexamples: seven pairs in template-fanout-equivalence-golden.test.ts (an xml:lang that contradicts lang, a different lang under one xml:lang, aria-hidden on <html>, on <body>, a missing favicon, a favicon in another format, the same favicons in another order). Each asserts that the two pages share a chrome key, that the rule's verdict really differs, and that nothing is inherited. A/B against main's template-fanout.ts: all fail on main and pass here. Signature tests add the review's positive control (a <body> class or <html dir> change leaves the signature alone) and a |-in-rel/href delimiter case.
  • Tripwire: packages/rules/tests/template-verdict-inputs.test.ts scans every rule the registry fans out (cross-checked against loadAllRules()). It sees literal selectors including the @squirrelscan/utils helpers, getAttribute/hasAttribute/getAttrCI/hasAttrCI, selector and attribute variables by name, .matches(), raw ctx.page.html, textContent, innerHTML, documentElement, doc.body, ctx.page.url, and every read in a package helper file a rule hands its document to (getCWVHints). Comments are stripped token-aware. The reads must equal a per-rule REVIEWED list, each marked KEYED or UNKEYED, so a new read fails CI and so does a stale entry. The VerdictScope doc (packages/rules/src/types.ts) now names every unkeyed input by rule, plus three things no entry captures (order of the sorted script/stylesheet/meta lists, <noscript> ancestry, head placement), and the test fails if a rule with an unkeyed read is missing from the doc. The unkeyed reads themselves (raw-HTML rules, inline script/style bodies, CWV hints, third-party-cookies images and iframes, landmark-one-main id/class) are left for perf(audit-engine): derive the template fan-out signature from what the declared rules read, with a parity test #585.
  • Re-measure: benchmarks/2026-09-perf-program.md has a Template fan-out key misses html lang, body aria-hidden and favicon links that template rules read #614 section. Same method as the The template cluster key does not constrain every input a fanned rule reads #275 table (one pass, chrome key and both signatures, no rules run). gymshark (the 2026-09-22 crawl, 3983 auditable): previous key 52 clusters / 3931 inherited, with Template fan-out key misses html lang, body aria-hidden and favicon links that template rules read #614 72 / 3911 (20 pages, 0.5%). openelectricity (fresh --level full -m 250 crawl, 2026-10-11): 11 / 239 both. On both crawls the previous key reproduces its existing row.

Note: the signature hash changes for every page, so cached fan-out groups regroup on the next run.

Gates: tsgo --noEmit clean in audit-engine and rules. Passing: template-fanout-equivalence-golden, template-fanout-parity-golden, template-cluster-key-golden (95), template-verdict-inputs, rule-verdict-scope, template-verdict-page-independence. A mutation check (an extra querySelector("h1") in core/favicon) turns the tripwire red. Three codex passes, none open.

Docs: no user-facing docs change (engine internals). Skill: no change needed.

@nc9
nc9 marked this pull request as ready for review October 9, 2026 16:38
@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review of #621: no blocking issues found.

  • (low) template-fanout.ts: the icon selector link[rel*="icon"] matches the rule's own fallback selector in core/favicon.ts, so coverage is right. The match is case-sensitive on both sides, so they stay consistent. If the rule is ever tightened, update both.
  • (low) Hashing the full href means pages with per-page-varying icon URLs (cache-busting query strings, for example) will no longer fan out. That is correct, but it may lower cluster counts. The re-measure in criterion 3 should show whether the effect is material.
  • (nit) roots uses querySelectorAll("html") and querySelectorAll("body") where a single lookup would do. That is harmless, and it does cover odd DOMs.
  • (nit) The test only checks that signatures differ. A positive control would also help: identical inputs, with a differing class on <body>, should give the same signature. That would confirm the signature is not over-sensitive.
  • (low) Criterion 2, the tripwire test, is deferred. Until it exists, the next template rule that reads a new input can silently reintroduce this bug. Please track it in a follow-up issue.

The CHANGELOG entry is fine. The note that cached groups regroup on the next run is accurate.

@nc9
nc9 force-pushed the fix/template-key-614 branch from 1c4aa11 to e1dbafb Compare October 11, 2026 03:29
@claude

claude Bot commented Oct 11, 2026

Copy link
Copy Markdown

Review of #621: I read the diff of template-fanout.ts and the types.ts docs, but did not run the tests or read the new tripwire test in detail.

  • (nit) packages/audit-engine/src/template-fanout.ts: roots is built in document order with html before body. That's fine, since the order is deterministic for a given parse. A single querySelector would also do, because querySelectorAll('html') and querySelectorAll('body') each return at most one element.
  • (nit) getAttribute returns null for a missing attribute and "" for an empty one. JSON.stringify keeps the two apart, which is correct for aria-hidden. Worth a one-line comment saying the distinction is deliberate.
  • (low) The favicon key uses link[rel*="icon"], while the core/favicon selectors are only reviewed by hand, as the types.ts docs say. If the rule ever adds a selector outside rel*=icon (for example a <meta name=msapplication-TileImage>), the tripwire won't catch it. Naming the selector variables in the REVIEWED list would close that gap.
  • (low) Icon href is hashed as written, so relative and absolute forms of the same URL now produce different keys. That only costs some fan-out efficiency and is not a correctness problem.

The change is correct and tight. It has counterexample tests, a positive control and a delimiter case, and the docs are updated. I found nothing that should block the merge.

@nc9

nc9 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor Author

Review triage (integrator, head e1dbafb):

  • (low) core/favicon selector variable reviewed by hand: deliberate. The tripwire records a selector held in a variable by the variable's name (selector:selector in the REVIEWED entry), and the VerdictScope doc in packages/rules/src/types.ts states that what the variable holds is a hand review. Seeing through variables, i.e. deriving the key from what the rules actually read, is perf(audit-engine): derive the template fan-out signature from what the declared rules read, with a parity test #585.
  • (low) icon href keyed as written, so relative and absolute forms of one URL split: deliberate. As the review says, it only costs fan-out efficiency, never a shared wrong verdict; resolving hrefs against the page URL would put a per-page input into the signature.
  • (nit) single querySelector for html/body and the null vs "" comment: left as is, behaviour is correct and deterministic.

@claude

claude Bot commented Oct 11, 2026

Copy link
Copy Markdown

Reviewed the diff: I found no issues.

  • fanoutInputSignature now covers <html> lang, xml:lang and aria-hidden, <body> aria-hidden, and icon link rel and href. That matches what a11y/html-xml-lang-mismatch, a11y/aria-hidden-body and core/favicon read.
  • Values are JSON-encoded, so a delimiter inside a value can't forge a boundary. Icon links stay in document order, which matches how core/favicon lists formats.
  • Each new input has a counterexample test that checks the chrome key is equal, the verdicts differ, and nothing is inherited. A positive control confirms that unread attributes such as class and dir don't change the signature.
  • The new template-verdict-inputs tripwire test and the VerdictScope doc update record which inputs are still unkeyed.

I did not run the tests or check CI status.

🤖 Generated with Claude Code

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.

Template fan-out key misses html lang, body aria-hidden and favicon links that template rules read

1 participant