Skip to content

fix(audit-engine): group template fan-out on the rule inputs the chrome key misses - #580

Merged
nc9 merged 14 commits into
mainfrom
claude/template-cluster-key-275-aqf16i
Oct 9, 2026
Merged

nc9 merged 14 commits into
mainfrom
claude/template-cluster-key-275-aqf16i

Conversation

@nc9

@nc9 nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Refs #275

The fan-out grouping key is now the chrome key, the page origin and a rule-input signature (sorted <script src> list, set of <meta> names, <main> landmark count). The stored template_fp is unchanged, so templateClusters() and the parity gate are unaffected. The cost of the tighter key is fan-out coverage only, never output.

Acceptance criteria

  • Cluster count and inheriting pages measured on gymshark.com and openelectricity.org.au, current and tightened key, recorded in benchmarks/2026-09-perf-program.md. Measured at landing (2026-10-10): gymshark (3983 auditable pages) 37 clusters / 3946 inherited on main's key, 52 / 3931 on the tightened key; openelectricity (fresh 250-page crawl, because the August crawls had lost their HTML to content-store pruning) 11 / 239 on both. --verify on openelectricity is byte-identical on both keys. Gymshark's --verify did not finish in 40 minutes, so its byte-identity is not recorded.
  • Decision recorded on which option ships, with justification. Option 1 (tighten the grouping key) is recorded in benchmarks/2026-09-perf-program.md. The justification is the constructed counterexamples, plus the real-crawl measurement above: the tighter key costs 0.4% of inherited pages on gymshark and nothing on openelectricity.
  • If the key is tightened, the equivalence golden gains a counterexample case that fails under the old key and passes under the new one. Three cases in template-fanout-equivalence-golden.test.ts (missing viewport meta, second <main>, script path differing on one host). I confirmed all three fail with the signature removed and pass with it. A unit test also covers fanoutInputSignature.
  • Limitation stated where a rule author reads it. The VerdictScope doc in packages/rules/src/types.ts now describes what the grouping key covers and what it still does not.

Checks run

  • template-fanout-equivalence-golden, template-fanout-parity-golden, template-cluster-key-golden (audit-engine) and rule-verdict-scope (rules): all pass
  • typecheck of audit-engine and rules, root format:check: clean
  • detect-secrets is not installed here; I grepped the diff for secret-like strings and found none

Agent skill

No change needed. This is an internal grouping change. CHANGELOG has a Fixed entry, because cloud audits (and CLI runs with SQUIRREL_RULE_CACHE=0) could inherit a wrong verdict before it.


Generated by Claude Code

…me key misses

The fan-out grouped on chrome plus origin, so two pages with the same chrome
but a missing viewport meta, a second main landmark or a different script path
on one host shared a verdict. Add a rule-input signature (script srcs, meta
names, main count) to the fan-out grouping key only; the stored template_fp is
unchanged. Pin the three counterexamples in the equivalence golden test.

Refs #275

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

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Status: waiting on the bot review. The code and tests are done and green locally. The one unmet criterion is the real-crawl measurement (criterion 1), which needs the gymshark.com and openelectricity.org.au crawls.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #580 (tighten fan-out grouping key, #275). The change is small and well scoped. I did not run the tests.

  • (medium) template-fanout.ts fanoutClusterKey: inputSignature defaults to "", so any caller that forgets the third argument silently falls back to the old chrome-only key. That is the unsafe direction. Make the parameter required (string | null) so the compiler catches omissions. The existing origin test would then need to pass an explicit value.
  • (low) fanoutInputSignature only covers what the three counterexamples read. Other markup inputs that declared rules read are still outside the key. The types.ts doc says this honestly. Consider a parity-gate check that fails when a declared rule reads inputs outside the signature, rather than relying on authors to remember.
  • (low) The signature reads <meta> names but not content. mobile/viewport can pass or fail on the viewport content value, for example width=device-width against a fixed width. Two pages with a viewport meta of different content would still share a verdict. Either include content for the meta names that rules inspect, or confirm that no declared rule reads it.
  • (low) script[src] is hashed from the raw attribute, not resolved against the page URL. That is safe, since it can only split groups more. It also means relative-path bundles that differ per route reduce fan-out. The doc already notes that the cost is coverage, not output.
  • (nit) The doc says the cluster counts on gymshark.com and openelectricity.org.au are not measured. Fan-out coverage may drop sharply with per-route hashed bundles, so please record those numbers in a follow-up before relying on the perf claims.
  • (nit) fnv1a64 is a non-cryptographic 64-bit hash, so a collision is theoretically possible. A collision would wrongly share a verdict. The risk is negligible at this scale, but you could key on the canonical string itself if memory allows.
  • (nit) The comment edit in template-fanout.ts ("Besides that, two things are NOT left to the declaration, because they are properties of the PAGE rather") now reads awkwardly across the line wrap.

Test coverage is good. The three counterexamples assert both that the premise holds and that fannedPages is 0, and there is a unit test for the signature. A test that the same-signature case still fans out would guard against over-tightening.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Round 1 addressed in f59a51b:

  • (medium) inputSignature is now a required parameter, so a caller that omits it fails typecheck instead of falling back to the chrome-only key.
  • (low) Viewport content is now part of the signature, since mobile/viewport reads it. There is a new counterexample case (width=device-width against width=1024).
  • (nit) I reworded the wrapped comment in template-fanout.ts.

Not changed:

  • Raw script src is kept on purpose. It can only split groups more, never merge them.
  • The fnv1a64 collision risk is negligible at a handful of clusters per crawl and is the same hash the existing key uses.
  • The gymshark and openelectricity numbers are the known open item, already stated in the PR body.
  • "Same signature still fans out" is already covered: the corpus tests assert 8 fanned pages and 5 clusters.
  • A parity check that flags declared rules reading inputs outside the signature is a larger follow-up, out of scope here.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewed the diff. The approach is sound: the stored template_fp is untouched and the fan-out key only gets tighter, so the failure mode is lost coverage, not wrong output. I only read the diff and grepped; I did not run the tests.

  • (medium) packages/audit-engine/src/template-fanout.ts (fanoutInputSignature): only the viewport <meta> includes its content. Every other meta contributes its name only. Two pages with the same chrome and the same meta names can still differ in robots (noindex vs index), description or og:* content. Any declared rule that reads those values would still inherit a verdict across them, which is the same class of bug as The template cluster key does not constrain every input a fanned rule reads #275. Please check the declared-rule list for meta-content readers. Then either add their content to the signature or say so in the VerdictScope doc.
  • (medium) Acceptance criterion 1 (cluster and inherited-page counts on gymshark.com and openelectricity.org.au) is not met, as the PR says. The key now includes the sorted script-src list. Sites with per-route hashed bundles may drop to near-zero fan-out, which would erase the perf win this feature exists for. That is a coverage risk, not a correctness one, but it should be measured before the decision is treated as final.
  • (low) The signature is a 64-bit FNV-1a of the canonical JSON. That is fine for accidental collisions, but a collision silently copies a verdict. Using the canonical string itself, or a longer hash, would remove that risk. fnv1a64 also loops with BigInt per byte on every page, which is avoidable CPU for pages with many scripts and metas.
  • (low) The signature uses the raw src attribute, not the resolved URL. Equivalent relative and absolute forms split into separate groups. That is safe but costs coverage.
  • (nit) streaming.ts: the comment above clusterKey still describes only the origin, so mention the signature there too.
  • (nit) The fanoutClusterKey tests pass "" as the signature. A real one is 16 hex chars, so use a realistic placeholder.

Test coverage is good. The counterexample cases check that the reference results actually differ and that fannedPages is 0. I'd add a positive case: two pages with an identical signature should still fan out. Without one, a signature that never matches would pass every test here.

…n the fan-out signature

Refs #275

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

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Round 2 addressed:

  • (medium) I checked the declared rules for meta-value readers. They are mobile/viewport, a11y/zoom-disabled, mobile/viewport-zoom, local/geo-meta and a11y/meta-refresh. The signature now includes content for viewport, geo.region, geo.placename, geo.position, icbm and http-equiv=refresh, and there is a new meta-refresh counterexample test. No declared rule reads robots, description or og:*, so those stay name-only.
  • (medium) Coverage measurement: still open, as stated in the PR body and the benchmark doc. It needs the real crawls, so the decision stays provisional until someone records the numbers.
  • (nit) The streaming.ts comment now mentions the signature. The origin tests use a realistic 16-hex placeholder.
  • Positive case added: identical signatures group and fan out, so the key cannot be vacuously tight. The corpus test also still asserts 8 fanned pages.
  • Not changed: raw src and the FNV hash, as in round 1. The hash cost is a single pass over a short canonical string per page, which is small next to the rule run it replaces.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #580 (tighten fan-out grouping key). The approach is sound: the stored template_fp stays unchanged, the new key is strictly tighter, and the tests pin each counterexample against a resident-run reference. I only read the diff and spot-checked the rules. I did not run the tests.

  • (medium) template-fanout.ts fanoutInputSignature: the content of a meta is only in the key for viewport, geo.* and ICBM, and for http-equiv refresh. Rules also read og:* and application-name metas, and some read Content-Type/charset values. Two pages that share the chrome key but differ in og:image presence are separated by the name set. A page with the same names but a different value, such as an og:image that is empty on one page, is not separated. The CONTENT_READ_METAS list will drift as rules change. Consider hashing all meta contents, or adding a test that enumerates the metas the declared rules read.
  • (medium) fanoutInputSignature: the signature reads querySelectorAll("meta") and script[src] across the whole document. Some rules use querySelectorAllOutsideNoscript and others do not. This is only conservative, so it is safe, but it can split clusters needlessly. Since coverage is the stated cost of the change, the benchmark numbers (see below) matter.
  • (low) benchmarks/2026-09-perf-program.md: the doc says cluster and inherited-page counts on gymshark.com and openelectricity.org.au are not measured. If real crawls collapse the fan-out (per-route hashed bundles are exactly what changes the script list), this could remove most of the perf win. Run template-fanout-bench.ts --verify before relying on the change. I would not call that a blocker for correctness.
  • (low) fanoutInputSignature: the doc parameter type is a hand-rolled structural type. Fine, but it duplicates parsed.document's type. Using that type directly would keep the two in sync.
  • (low) Tests: the counterexample list does not include a case where metas differ only in content of og:*, or a [role="main"] landmark. The unit test covers <main> counts only.
  • (nit) The doc comment for CONTENT_READ_METAS sits between fanoutInputSignature's JSDoc and the function, so the JSDoc attaches to the constant. Move the constant above the JSDoc.
  • (nit) .sort() on the deduplicated lists uses the default code-unit order. That is deterministic, so it is fine.

No critical or high-severity issues found.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Round 3 (final): no critical or high findings.

  • (nit, fixed) The CONTENT_READ_METAS constant now sits above the JSDoc, so the JSDoc attaches to fanoutInputSignature.
  • (low, fixed) The unit test now covers a [role="main"] landmark.
  • (medium, not changed) I grepped every rule declaring verdictScope: "template" for meta readers. Only viewport, zoom-disabled, viewport-zoom, geo-meta and meta-refresh read meta at all, and no declared rule reads og:*, application-name or any Content-Type meta. Hashing every meta's content would split nearly every page, because description and og:* differ per page, and that would remove the fan-out for no verdict benefit. The list is derived from the declared rules. A rule added later that reads a meta value has to extend it, and the VerdictScope doc says so.
  • (medium, not changed) querySelectorAll versus querySelectorAllOutsideNoscript: the wider scan is conservative, as the review says. The coverage effect is part of the measurement still owed on the real crawls.
  • (low, not changed) The doc type is structural on purpose. audit-engine does not depend on linkedom types.
  • Benchmark numbers: still the open item, as stated in the PR body.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #580 (tighten template fan-out grouping key, #275). I read the diff and checked the call sites. I did not run the tests.

  • (medium) `template-fanout.ts` (`fanoutInputSignature`): the signature only covers script `src`, meta names, a few meta `content` values and the `` count. The updated doc in `types.ts` admits that other inputs (`` rel, headings, attributes) are still uncovered. The PR therefore closes the three constructed counterexamples but not the class of bug. Consider a follow-up that derives the signature from what the declared rules actually read, or a parity test that fails when a declared rule reads an input outside the signature.
  • (medium) `benchmarks/2026-09-perf-program.md`: the cluster and inherited-page counts on gymshark.com and openelectricity.org.au are not measured. The PR says so openly, which is good. The risk is that the tighter key makes fan-out coverage collapse on sites with per-route hashed bundles, because the script path is now part of the key. That could erase most of the perf win. Please run `template-fanout-bench.ts --verify` before relying on this, or track it as a blocking follow-up.
  • (low) `fanoutInputSignature`: per-page script paths such as `/_next/static//page-xyz.js` make nearly every page a singleton cluster. Normalising or excluding same-origin scripts is unsafe only for `security/sri`, which cares about cross-origin scripts. Keying on the cross-origin subset only would keep most of the coverage while preserving correctness.
  • (low) `fanoutInputSignature`: `Array.from(querySelectorAll)` with one `getAttribute` call per attribute is fine. The DOM walk runs for every page even when no declared rule is eligible, so consider skipping it when `fanout` is null. In `streaming.ts` the call is already guarded by `fanout ?`, so this is fine as written.
  • (nit) the meta element is lower-cased before `CONTENT_READ_METAS` is checked, but `http-equiv` is compared lower-cased only in the ternary. Both are fine. A short comment explaining that operator precedence groups the `||` before the `?:` would help readers.
  • (nit) Tests are good: five counterexamples plus the grouping-still-works assertion. A test that a page with a null document never groups, exercised through `streamPageRules`, would round it out.

No correctness blockers found: `parsed.document` is still live at the call site, and the `NUL` join stays injective.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

This review reports no correctness blockers, and the three review rounds are used, so I'm not pushing again. Where each point stands:

  • Class of bug versus the three counterexamples (medium): agreed that this closes the constructed counterexamples, not the whole class. A parity check that fails when a declared rule reads an input outside the signature is the right follow-up, and I'm leaving it for the maintainer to file.
  • Coverage on real crawls (medium): this is open criterion 1, already stated in the PR body and the benchmark doc. It needs the gymshark.com and openelectricity.org.au crawls and template-fanout-bench.ts --verify.
  • Keying on cross-origin scripts only (low): worth testing against that measurement. The issue's own /assets/a.js against /assets/b.js counterexample is on one host, and security/sri names the resource url, so dropping same-origin scripts could re-open it. I'd decide it from the measured numbers, not up front.
  • Remaining nits: these are optional and I'm not acting on them in this PR.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #580 (fan-out grouping key tightened with fanoutInputSignature). I read the diff only. I did not run the tests or the bench.

The approach is sound: the stored template_fp is unchanged, the signature goes only into the grouping key, and the cost is coverage rather than output. The tests are good. They include a premise check that the reference results really differ, plus a positive check that identical inputs still group.

  • (medium) template-fanout.ts (fanoutInputSignature): the full sorted <script src> list goes into the key, and sites with per-route hashed bundles are the case this PR targets. On those sites most pages will get a unique key and fan-out will stop saving work. The PR's own benchmark note says cluster and inherited-page counts on gymshark.com and openelectricity.org.au were not measured. The perf program depends on those numbers, so I'd record them before merge, or at least confirm the change is not a large throughput regression. Narrowing the signature to scripts whose URL security/sri actually evaluates (cross-origin or missing integrity) would keep more coverage.
  • (low) fanoutInputSignature runs two or three querySelectorAll passes on every page, including pages that are never fanned out. Computing it only when fanout is enabled and the template key is non-null would avoid that. The call is already behind fanout ?, so this is minor.
  • (low) CONTENT_READ_METAS is a hand-maintained list that mirrors what individual rules read (viewport, geo.*, icbm, refresh). Nothing ties it to the rules, so a new rule that reads another meta's content will silently reintroduce the bug. The updated types.ts doc says to extend the signature. A test that scans declared rules, or at least a comment in each declaring rule, would make that safer.
  • (nit) Meta entries lowercase every value, including content. content=0;url=/X and content=0;url=/x therefore collapse into one group. That is harmless for the rules listed, but it is wrong in principle for URL targets. Lowercase the names only.
  • (nit) The meta charset value is dropped (only presence is kept). That is fine as long as no rule reads its value.

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Coverage measurement on synthetic estates, as requested. This is not the real-crawl measurement: the gymshark.com and openelectricity.org.au crawls are not available in this VM, and template-fanout-bench.ts needs a finished project.db, so I ran streamPageRules directly over in-memory estates. Each estate has 360 pages and 6 chrome templates. Each arm ran in its own process, and the fan-out result was compared with a no-fan-out run in the same process, page by page (the same comparison as --verify).

estate main: clusters / inherited main: fanned equals reference branch: clusters / inherited branch: fanned equals reference
stable bundles (2 per template) 6 / 354 yes 6 / 354 yes
per-route hashed chunks (5 routes per template, each chunk shared by its route's pages) 6 / 354 no, 36 pages differ 30 / 330 yes
hashed chunk on every third page only 6 / 354 no, 120 pages differ 126 / 234 yes
worst case: unique hashed chunk name on every page 6 / 354 no, 2 pages differ 360 / 0 yes

Time: wall and CPU were within 10% between arms and between main and the branch, at about 2.5 to 2.9 s wall per run for the whole rule pass. At 360 pages the fan-out saving (about 3 to 10%) is inside that noise, so time is not a usable result here. The counts are the result.

What it says:

  • A stable-bundle site loses nothing. A realistic per-route estate keeps 330 of 354 inherited pages.
  • Only the unique-name-per-page worst case collapses to 0 inherited. A real route does not produce that, because every page of a route shares its chunk.
  • main inherits more, but it is wrong on every estate where pages with one chrome load different bundles. In the 2-page case the differing rule is js-libraries-detected, which matched a library name inside a hash.

I also tried your suggested fix, a stem key that replaces hash-like tokens in the script name with #. It recovered the worst case to 354 inherited, but fanned results then differed from the reference on the same 2 pages as main, because a rule can match inside a hash. Byte-identity is the claim this feature rests on, so I reverted that and kept the full script name in the key.

One small code change in the same push: meta names and values are no longer lowercased in the signature (the nit from the last review). This is safe, and at worst it splits groups more.

Pushed as 38aa3d1 (plus a merge of the remote main merge). The synthetic table is also recorded in benchmarks/2026-09-perf-program.md. The real-crawl numbers are still the open criterion 1. The equivalence test file (18 tests) and the parity golden (53 tests) pass, and typecheck and format:check are clean. I did not merge.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #580 (tighter fan-out grouping key). The approach is sound, and the docs and golden tests are thorough. I found one real gap in the key.

  • (high) packages/audit-engine/src/template-fanout.ts (fanoutInputSignature): the signature covers only the src of each <script>. security/sri has verdictScope: "template" and reads script.getAttribute("integrity") (sri.ts:94). It also reads link[rel~=stylesheet][href] and the integrity on those links (sri.ts:102-110). Two pages with the same chrome key and the same script list, where one has integrity= and the other doesn't, get the same signature. The second page would inherit the first page's verdict, which breaks the byte-identity claim. Fix it by adding integrity (and crossorigin) to each script entry, and the stylesheet/link hrefs and integrity as well. Add a golden counterexample for it. This is the same class of bug as the three counterexamples this PR closes.
  • (medium) template-fanout.ts, script and meta de-duplication: [...new Set(scripts)] and [...new Set(metas)] collapse duplicates. Two viewport metas versus one, or a script included twice versus once, produce the same signature. A rule that counts duplicates (for example duplicate-viewport-style checks) would inherit a wrong verdict. Sort without de-duplicating; it's cheap and strictly safer.
  • (medium) The meta entry joins name, property and http-equiv with the same | and drops the null ones. <meta name="x"> and <meta property="x"> therefore hash identically. Prefix each part with its attribute name. Also, content is hashed only for the allowlisted metas, so that list has to stay in sync with the rules by hand. A test that fails when a template-scoped rule reads meta[name=…] content outside CONTENT_READ_METAS would catch drift.
  • (low) querySelectorAllOutsideNoscript is used by sri but the signature uses plain querySelectorAll. This errs conservative (more splits), but it means a <noscript> script change splits groups needlessly. Also, fanoutInputSignature runs 3 selector scans per page on the hot path. The benchmark shows no measurable overhead at 360 pages, so it's probably fine, but I'd check it on a large crawl.
  • (nit) The benchmark doc says real-crawl counts are still not recorded. Consider opening a follow-up issue to track that.

Test coverage is good: there are 5 counterexamples, and the signature unit test checks that equal inputs still group.

…in the fan-out signature

Refs #275

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

nc9 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor Author

Addressed in one more push. This is past the usual three review rounds; I fixed it anyway because I confirmed it is a real correctness gap in this PR.

  • (high) Confirmed: security/sri reads integrity on cross-origin scripts and on link[rel~=stylesheet] (sri.ts:94 and :108). The signature now carries whether each <script src> and each stylesheet link has an integrity attribute. There are two new golden counterexamples (a script gaining integrity, a stylesheet gaining integrity).
  • (medium) Scripts, stylesheets and metas are no longer de-duplicated, only sorted, so a doubled viewport meta or a doubled script no longer matches a single one.
  • (medium) Each meta part is now keyed by its attribute, so name="x" and property="x" differ.
  • (medium) New drift guard: a test scans every rule declaring verdictScope: "template" for meta[name="..."] selectors and fails if the name is not in CONTENT_READ_METAS (now exported).
  • (low) Plain querySelectorAll stays: it only ever splits groups more than querySelectorAllOutsideNoscript would. The synthetic estates showed no measurable cost at 360 pages.
  • (nit) The real-crawl numbers are criterion 1 on the issue itself, so I left that tracked there.

All seven counterexample cases fail with the signature removed and pass with it. The equivalence file (21 tests) and the parity golden (53) pass, and typecheck and format:check are clean.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #580. The approach is sound: the stored template_fp is unchanged and the fan-out key only gets tighter, so output is not affected. The counterexample goldens assert against the resident reference run, which is the right oracle. The PR is also upfront that the real-crawl acceptance item is not met.

  • (medium) packages/audit-engine/src/template-fanout.ts:fanoutInputSignature Several rules that declare verdictScope: "template" read inputs that are still not in the key. I confirmed these in the rule sources:

    • a11y/html-xml-lang-mismatch reads <html lang> and xml:lang.
    • a11y/aria-hidden-body reads aria-hidden on <html> and <body>.
    • core/favicon reads the <link rel=icon> hrefs.

    Two pages with the same chrome key but a different <html lang> or aria-hidden="true" on body would still inherit a verdict. This is the same class of bug as The template cluster key does not constrain every input a fanned rule reads #275. The types.ts doc admits that "any other input" is uncovered. For these rules that is a known gap rather than a hypothetical one. Either add them to the signature, with golden counterexamples, or open a follow-up issue and say so in the PR. Adding <html> attributes and the icon link hrefs is cheap.

  • (medium) benchmarks/2026-09-perf-program.md and the types.ts doc The decision is recorded as provisional, and the gymshark and openelectricity numbers are missing. A maintainer needs to run template-fanout-bench.ts --verify before this closes The template cluster key does not constrain every input a fanned rule reads #275. The PR body says it only Refs The template cluster key does not constrain every input a fanned rule reads #275, which is appropriate. Keep it that way until the figures are in.

  • (low) types.ts and the benchmark doc describe the signature as "script list, meta names, main count". The code also includes integrity presence, stylesheet hrefs, and content for the viewport, geo, ICBM and refresh metas. Update the docs so a rule author reads the real key.

  • (low) template-fanout-equivalence-golden.test.ts (the CONTENT_READ_METAS guard) The guard is a regex over meta[name="x"] in files that contain verdictScope: "template". It misses rules that read meta content through helpers, getAttribute loops, or a shared util, and it also fires on any template-scoped file that mentions a meta in a comment. It is a useful tripwire but not proof. The comment says "kept honest", which overstates what it does.

  • (low) fanoutInputSignature runs three or four querySelectorAll calls plus a JSON stringify and hash on every page when fan-out is on. That is cheap next to running the rules. The benchmark shows no measurable difference at 360 pages, which is fine, but it was not measured on a large crawl.

  • (nit) template-fanout.ts The comment on the scripts and stylesheets constants has an over-long line that wraps awkwardly. Run it through the formatter. meta[name] matching is also case-sensitive in the selector but lowercased in CONTENT_READ_METAS, which is harmless but inconsistent.

  • (nit) scripts.sort() and the other sorts use the default string order. That is deterministic, so it is fine.

No security concerns. Overall this is a safe, conservative change. I would address the <html>, body and favicon gap, or track it explicitly, before merging.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Review of #580 (tighten fan-out grouping key, #275)

The design is sound. The grouping key gets tighter and the stored template_fp is untouched. Cost is fan-out coverage, never output. The counterexample tests assert the premise (reference verdicts differ) and then assert no inheritance, which is the right shape. I only read the diff and did not run the tests.

  • (medium) template-fanout-equivalence-golden.test.ts, CONTENT_READ_METAS guard: it only matches the literal regex meta[name="..."] in files that contain verdictScope: "template". A rule that reads a meta via getAttribute, a different selector form (meta[name=viewport i], meta[http-equiv=...]), or a helper in another file would slip past it. The comment says it "keeps the list honest", which is stronger than what it enforces. Consider narrowing the claim in the comment, or covering more selector forms.
  • (low) Docs and comments drift from the code. benchmarks/...md, types.ts and the streaming.ts comment describe the signature as script srcs, meta names and the main count. The implementation also hashes stylesheet hrefs and integrity presence, plus content for viewport, geo.*, ICBM and refresh. The numbers in the benchmark table only model the script list. Please update the description so a rule author knows what is actually keyed.
  • (low) The benchmark section says real-crawl counts (gymshark, openelectricity) are not recorded, and the evidence is synthetic estates. That is honestly disclosed. Still, per-route hashed bundles are common, so coverage may drop a lot on real sites (the worst case goes to 0 inherited). A follow-up with real numbers would be worthwhile before relying on fan-out for the perf claims.
  • (low) fanoutInputSignature runs 4 querySelectorAll calls plus a JSON stringify and hash on every page when fan-out is on. This is probably small next to rule execution, but the claim of "within 10%" at 360 pages is within noise. Consider computing it only when fanout is non-null. The call site already does that, so this is fine as is.
  • (nit) The fanoutInputSignature doc comment has an awkwardly wrapped line ("...and the same for stylesheet links, sorted and not de-duplicated: security/sri reports..."). Reflow it.
  • (nit) The doc parameter type is a hand-rolled structural type. A named interface would be easier to read and reuse.

No critical or high issues found.

@claude

claude Bot commented Oct 8, 2026

Copy link
Copy Markdown

Reviewed the diff. The approach is sound: widening only the fan-out key, with template_fp untouched, keeps the parity gate's definition stable, and the failure mode is lost coverage, never wrong output. The only caller of fanoutClusterKey (streaming.ts) is updated.

  • (medium) benchmarks/2026-09-perf-program.md: the acceptance criterion for real-crawl numbers (gymshark, openelectricity) is not met, and the PR says so. The decision to ship is therefore provisional. The synthetic table is useful, but the claim that a real route does not produce a unique chunk name per page is untested. Pages with a build id, nonce or cache-busting ?v= in a script src would drop fan-out to near zero, and the benchmark doesn't cover that. A maintainer should run template-fanout-bench.ts --verify before this is treated as settled.
  • (medium) packages/audit-engine/src/template-fanout.ts (fanoutInputSignature): the PR description, the VerdictScope doc in types.ts and the benchmark doc all say the signature is "script srcs, meta names, main count". The code also hashes stylesheet hrefs, integrity presence, and content for viewport, geo.*, ICBM and meta refresh. That is the right call, but the docs understate the key. A rule author reading types.ts would conclude that stylesheets and meta content are not covered. Please update the docs to match the code.
  • (low) Cache-busting query strings (src="/a.js?v=123") would make every page a unique group. If no rule reads the query part, stripping it would be safe. The PR already rejected hash normalisation for byte-identity reasons, so this is only worth a note.
  • (low) The CONTENT_READ_METAS guard test only matches the literal meta[name="x"] selector form in files containing verdictScope: "template". A rule that reads meta content through a helper, a variable selector or a loop over querySelectorAllOutsideNoscript(doc, "meta") (as local/geo-meta also does) would not be caught. The comment says the test keeps the list "honest", which overstates it. Soften the comment or note the limitation.
  • (low) That test builds the rules directory with new URL(...).pathname, which breaks on Windows paths and on paths with spaces. Prefer fileURLToPath or import.meta.dir.
  • (low) Each page now runs four querySelectorAll calls, a sort and an fnv hash even when it would never fan out. This is small next to the rule runs it saves, and the benchmark shows no measurable change.
  • (nit) Meta name case is kept as-is in the signature (Viewport and viewport differ). That is conservative and only costs coverage.
  • (nit) The stylesheet part of the signature is only covered through the SRI case, not in the fanoutInputSignature unit test.

Test coverage is good: seven counterexamples are each compared against the resident reference run, plus a positive grouping check and a null-signature check. I could not run the tests in this environment.

Nik Cubrilovic added 3 commits October 9, 2026 23:10
* origin/main:
  feat(core-contracts): audit levels definition (quick, surface, full) (#602)
  test(rules): restore the real fetch when a graphql test stubs twice (#599)
  chore(release): v0.0.107 (#595)
  docs(changelog): release notes for v0.0.107 (#594)
  feat(rules): add GraphQL introspection and GET mutation probing rules (#593)
  fix(audit-engine): keep paid cloud prefetch results when the phase is abandoned (#582)
… is named

The VerdictScope doc, the streaming and template-fanout comments and the
benchmark note described the signature as script srcs, meta names and the
main count. It also keys stylesheet hrefs, integrity presence on both, every
meta's attribute names, and the content of the metas declared rules read the
value of. The CONTENT_READ_METAS test comment now says it is a tripwire for
the literal meta[name] form, not a proof.

Signed-off-by: Nik Cubrilovic <[email protected]>
* origin/main:
  feat(rules): escalate server-only secrets shipped in browser scripts to critical (#575)
  fix(rules): cap bad-caching validators at warn and note a Cloudflare-stripped ETag (#606)
…tricity crawls #275

Counted both keys in one pass over each crawl: gymshark (3983 auditable
pages) goes from 37 clusters / 3946 inherited to 52 / 3931, and a fresh
250-page openelectricity crawl stays at 11 / 239. --verify on openelectricity
is byte-identical on both keys; gymshark's --verify did not finish inside
40 minutes. Adds the CHANGELOG entry for the fix.

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

nc9 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Landing pass (pushed 6430f18): merged main (now including #575 and #606), fixed the docs drift from the last two reviews, and recorded the real-crawl numbers for criterion 1.

  • Criterion 1, measured. Both keys were counted in one pass over each crawl: parse, chrome key, fanoutInputSignature, first page is the representative, DEFAULT_MAX_CLUSTERS cap, no rules run. On openelectricity this method gives the same counts that streamPageRules itself reports.
    • gymshark, 3983 auditable pages: main's key gives 37 clusters / 3946 inherited, the tightened key 52 / 3931. That's 15 fewer inherited pages, 0.4%.
    • openelectricity, a fresh 250-page crawl: 11 / 239 on both keys. The August crawls had lost their HTML to content-store pruning, hence the new crawl.
    • template-fanout-bench.ts --verify on openelectricity is byte-identical with and without fan-out on both keys: 250 pages compared, 239 fanned, 5975 rule runs removed.
    • Gymshark's --verify did not finish in 40 minutes (2,340 s CPU, 1.7 GB), so its byte-identity is not recorded.
    • The per-route-bundle collapse the reviews worried about does not show up on either real site.
  • Docs drift (16:12 and 16:51 reviews): types.ts, the streaming.ts and template-fanout.ts comments, and the benchmark note now describe the whole signature: stylesheet hrefs, integrity presence, every meta's attribute names, and the content of the value-read metas. The CONTENT_READ_METAS test comment now calls itself a tripwire for the literal meta[name="…"] form, not a proof.
  • CHANGELOG: added a Fixed entry. Fan-out runs in cloud audits and in CLI runs with SQUIRREL_RULE_CACHE=0, so a wrongly inherited verdict was user-visible.
  • Not in this PR (15:50 review): a11y/html-xml-lang-mismatch (<html lang>, xml:lang), a11y/aria-hidden-body and core/favicon (link[rel*=icon] hrefs) still read inputs outside the key. The VerdictScope doc already says this, and main's key misses them too, so nothing regresses. They stay under The template cluster key does not constrain every input a fanned rule reads #275, which this PR only Refs, along with the follow-up of a parity check that derives the signature from what the declared rules read.
  • Gates: the equivalence, parity and cluster-key goldens (87 pass), the template tests in the replay golden, rule-verdict-scope and template-verdict-page-independence (411 pass), tsgo in audit-engine and rules, detect-secrets-hook, and docs make validate: all clean.

@claude

claude Bot commented Oct 9, 2026

Copy link
Copy Markdown

Review of #580 (tighten the template fan-out grouping key). I read the diff and the call sites; I did not run the tests.

The change is sound and the tests are good. The counterexample tests pin the premise (ref(a) != ref(b)), and the null signature never groups. fanoutClusterKey has only the one production caller, and it is updated.

  • (low) template-fanout.ts (fanoutInputSignature): the signature is reduced to a 64-bit FNV hash. A collision would silently copy a verdict between pages that differ. The odds are negligible, but the key is already an in-memory string, so using the canonical JSON (or a longer hash) would remove that class of error. fnv1a64 does a BigInt multiply per byte, which is slow on pages with many scripts and metas. Sites with large inline-free script lists will pay this on every page.
  • (low) fanoutInputSignature: inline <script> bodies, <link> tags other than stylesheets, and <script> tags that have src but different type/async attributes are not in the signature. The doc comment admits this. Rules reading those inputs rely on the declaration alone, so it is worth checking that no declared template rule reads them.
  • (low) The CONTENT_READ_METAS tripwire test only matches the literal meta[name="…"] form, and only in files containing verdictScope: "template". A rule that reads a meta via getAttribute or a helper will not be caught. The test's comment already says this.
  • (nit) CHANGELOG.md: the new Fixed entry sits under the v0.0.107 (2026-10-09) section, but the benchmark doc cites measurements from 2026-10-10. Check that the entry is under the right release heading.
  • (nit) benchmarks/2026-09-perf-program.md: the gymshark --verify run did not finish, so byte-identity on the large crawl is unrecorded. It is stated honestly, but the claim rests on the openelectricity crawl and the synthetic estates.

@nc9

nc9 commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Triage of the review at 14:00 (no blockers): the CHANGELOG ### Fixed entry is under ## [Unreleased]. The diff hunk ends just above the ## v0.0.107 heading, which is why it looked otherwise. The FNV-64 point was already answered in rounds 1 and 2, and the other inputs (inline bodies, other <link> rels, script attributes) are the same open class tracked on #275. Merging.

@nc9
nc9 merged commit 25aecef into main Oct 9, 2026
15 checks passed
@nc9
nc9 deleted the claude/template-cluster-key-275-aqf16i branch October 9, 2026 14:10
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.

1 participant