Skip to content

feat(rules): perf/framework-data-payload flags large framework state on static pages (#1143) - #1304

Closed
nc9 wants to merge 4 commits into
mainfrom
feat/framework-data-payload-1143
Closed

nc9 wants to merge 4 commits into
mainfrom
feat/framework-data-payload-1143

Conversation

@nc9

@nc9 nc9 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1143.

PR1 of the G6 pair. #1200 (perf/content-in-js-bundle) follows as a separate PR targeting main, depends on this one, and reuses packages/rules/src/shared/framework-payload.ts (bounded script reads, framework state detection).

What

New page-scope info rule perf/framework-data-payload: a page that is mostly text but carries a large inline framework payload (the same content shipped as markup and as JSON).

  • shared/framework-payload.ts (shared analyzer): findFrameworkPayloads(doc) names and sizes __NEXT_DATA__, Next.js app router self.__next_f flight chunks (summed), window.__NUXT__ and __NUXT_DATA__, window.__remixContext, __staticRouterHydrationData, Qwik qwik/json, SvelteKit __sveltekit_, __INITIAL_STATE__/__PRELOADED_STATE__/__APOLLO_STATE__, and Astro astro-island props. JSON-LD, import maps and ordinary scripts are not counted. measureInteractivity and visibleTextLength give the "static page" side.
  • Bounded on untrusted input: at most 2000 inline scripts and 500 islands read, the marker tests read the first 160 characters of a script, no pattern runs over a payload body, text length is a capped node walk, interactivity counts are capped per kind.
  • Reports (info) only when ALL hold: payload >= 100 KB (min_bytes), payload >= 20x visible text (min_text_ratio), form controls + embeds <= 5 (max_interactive), buttons <= 50 (max_buttons). Everything is an option.

Threshold evidence (smoke run, 40 public pages)

Next.js app router pages carried 50 to 460 KB of flight data against 1 to 8 KB of text (ratios 9 to 425). Pages router and Nuxt: 21 to 250 KB. Pages with no detectable payload (Remix, Astro, TanStack, Gatsby and others) report nothing. Interactive pages sit apart and are NOT flagged: a flexbox tutorial (45 form controls, 4 embeds, 155 KB payload vs 33 KB text), a component library home (19 form controls, 435 KB), a Next.js home with 7 form controls. Marketing, docs and blog pages with 0 to 4 form controls and 120 to 460 KB payloads are the ones flagged. One page (react.dev) measured 0 visible text in the node walk, so its ratio is not trusted and I did not tune on it. Raw numbers are in the rule docs summary, not the fixtures.

Four-file recipe and counts

  • Rule + registry: packages/rules/src/performance/framework-data-payload.ts, performance/index.ts.
  • Docs: docs/rules/perf/framework-data-payload.mdx, docs/docs.json nav, generated hub table, perf count 30 to 31 (docs/rules/index.mdx, docs/rules/performance/index.mdx), constants.ts comment 310 to 311. PUBLIC_RULE_COUNT_FLOOR (300) is unchanged: the live total moves to 311, inside floor + 50.
  • Tests: packages/rules/tests/framework-data-payload-1143.test.ts (14, synthetic pages shaped like the real ones: each framework, JSON-LD/importmap negative, noscript, deep marker, script cap, flagged, small, interactive, embeds, mostly-data, hidden inputs, options, no document); verdictScope page, listed in template-invariance-measured.json varyingRules (both corpora); canonical golden: perRuleTally 314 to 315, findings +500 (103244 to 103744), health score unchanged.
  • PRIVATE follow-up at release (not done here): regenerate the rule catalog, bump the totalRules literal in apps/web/src/components/rules.tsx, and the gitlink; the private rule-count guards read the public docs literals, which this PR updates. New total: previous + 1.

Verified / not

Verified: tsgo (rules), make validate, the new test, rule-verdict-scope, template-verdict-page-independence, template-verdict-inputs, docs-category-table, meta-string-limits, docs-rule-pages, the canonical golden; a local squirrel audit (dev entry, --offline --http) of a page with 160 KB of flight data ran the rule through the real engine (1 info check, 1 ms) and a control page passes. Not verified: the full scripts/test-suites.ts --run rules suite (left to CI); info checks are not shown in CLI JSON/LLM output (pub#669), so the live run was confirmed from the rule profile line, not the report.

Skill: no change needed (the skill does not list individual rules).

Caps on untrusted input (scan follow-up)

The analyzer reads pages an audited site controls, and never parses or runs a pattern over a payload body. Caps: 2,000 inline scripts and 500 astro-island elements read per page; a script is tested only on its first 160 characters (the rest is only measured by length); interactive element counts stop at 200 per kind; the text walk visits at most 200,000 nodes iteratively (no recursion, so deep nesting cannot overflow the stack); doc.body is read through a guard because linkedom throws on a rootless document. tests/framework-payload-adversarial-1143.test.ts feeds a 5 MB script of brackets, quotes and escapes, a marker repeated through 5 MB, 20,000 scripts, 5,000 islands, 15,000 interactive elements, 300,000 text nodes, 3,000-deep nesting and an empty document, asserting the caps hold (counts) with a 5 s ceiling; run three times locally with no flake.

Review round (g6)

  • A page with almost no visible text is no longer judged: below min_text_chars (default 1024) the rule passes ("too little to judge"). Before, zero text gave an infinite ratio, so client-rendered shells and measurement misses could read as "mostly text" pages. Tested with empty, <div id=root> and "Loading" shells carrying 300 KB of flight data.
  • documentBody: the other unguarded doc.body reads named in review (a11y/aria-hidden-body.ts:24, content/date-agreement.ts:456, page-classifier/src/comments-rule.ts:396) read documents that come from the parser's parseHTML. fix(parser,rules): empty-body pages and hostile ids no longer throw rule errors #1270 #1276 #1290 (open) wraps that function so a rootless document never reaches a rule, which covers all three at the root, so I did not touch those files; this PR's own guard stays as defence in depth. Rebase after fix(parser,rules): empty-body pages and hostile ids no longer throw rule errors #1270 #1276 #1290 if conflicts appear.

…on static pages (#1143)

New info rule and a shared payload analyzer: __NEXT_DATA__, the Next.js app router flight chunks, __NUXT__, Remix, Qwik, SvelteKit and Astro island state, sized per page with bounded reads. Reports only when the payload is at least 100 KB and 20 times the visible text on a page with at most 5 form controls and embeds and 50 buttons.

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

nc9 commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

Landed in v0.0.143 as a7ddb52c 78430d33 aefda9bd 0874e629 via #1341. Release: https://github.com/squirrelscan/squirrelscan/releases/tag/v0.0.143. Closing this original.

nik

@nc9 nc9 closed this Oct 30, 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.

perf: flag large framework data payloads on static pages

1 participant