Repository navigation
Description
Problem
Same incident as #425. A site's CSP left out hosts the site depends on, which silently broke a booking widget and blocked every GA4 hit and the Google Ads script for about three months. 8 squirrel audits ran in that window and none flagged it.
#425 catches this on rendered crawls. This rule catches most of it statically, on every audit, with no render.
Proposal
New per-page rule security/csp-blocks-own-resources:
-
Parse each page's CSP. Reuse the parser in
packages/rules/src/security/csp.ts, but note that rule only readsctx.site.pages[0]. Policies can differ per route. -
Collect what the page references:
<script src>,<link rel="modulepreload|preload">,<iframe src>, stylesheets, images- plus third-party script URLs found inside same-origin JS chunks.
The widget URL in this incident only appeared inside a preloaded module chunk. Script extraction in
packages/audit-engine/src/adapter.tsfollows plain same-domain<script src>only. -
Match each URL against its directive (
script-src(-elem),frame-src/child-src,style-src,img-src, falling back todefault-src). Use real CSP source matching: schemes,'self', host wildcards (*.example.comdoes not matchexample.com), ports, paths. -
Check hosts the HTML never names, via a vendor table. When tech detection finds a vendor, check the hosts it needs at runtime. Examples:
- GA4 / Google tag: connect
*.google-analytics.com,analytics.google.com,*.analytics.google.com,www.google.com,stats.g.doubleclick.net - Google Ads: script
googleads.g.doubleclick.net,www.googleadservices.com,www.google.com; frametd.doubleclick.net - Others: GTM, PostHog (
*.i.posthog.com), Stripe (js.stripe.com,api.stripe.com, frames), Turnstile, reCAPTCHA
Keep the table as data with a "last verified" date, because vendor hosts drift.
- GA4 / Google tag: connect
Severity: error when a blocked host belongs to a form/booking, analytics, ads, payments or captcha vendor; warn otherwise. The message names the directive and the host to add.
Acceptance
- Fixture: gtag for an Ads-linked property plus
connect-src 'self' https://www.google-analytics.com→ error listinganalytics.google.com,www.google.comandstats.g.doubleclick.netforconnect-src. - Fixture: a third-party script URL referenced only from a preloaded same-origin chunk, with its host not in
script-src→ finding. - Fixture:
https://*.example.cominscript-srcwith a script fromcdn.example.com→ pass; with a script fromexample.com→ finding. - No CSP header → rule passes (missing CSP is
security/csp's job).
Notes
- Cost: no render; one more pass over already-parsed HTML, plus chunk scanning.
- False-positive risk: low to medium. The risks are source-matching edge cases and vendor-host drift.
- Pairs with New rule: security/csp-violations - report what the browser actually blocked during rendered crawls #425, which reports what the browser actually blocked.
Acceptance Criteria
- Fixture: gtag for an Ads-linked property plus
connect-src 'self' https://www.google-analytics.comproduces an error listinganalytics.google.com,www.google.comandstats.g.doubleclick.netforconnect-src - Fixture: a third-party script URL referenced only from a preloaded same-origin JS chunk, with its host missing from
script-src, produces a finding - Fixture:
https://*.example.cominscript-srcpasses for a script fromcdn.example.comand produces a finding for a script fromexample.com - A page with no CSP header passes
security/csp-blocks-own-resources(missing CSP stays withsecurity/csp) - The rule evaluates each page's own CSP rather than only the first page's, and its vendor host table records a last-verified date; the rule has a docs page under
docs/rules/security/
Activity
nc9 commentedon Oct 8, 2026
Status: implementation is up in #583 (ready for review, waiting on the bot review). All five acceptance criteria have tests. Smoke on public sites was limited by sandbox egress: github.com (15 pages under an enforced CSP) and nodejs.org produced 0 findings, so 0 false positives in a small sample. No agent skill change needed.
nc9 commentedon Oct 8, 2026
Status: #583 is ready for human review. The bot review is down to lows and nits, CodeQL alerts are fixed, and all five acceptance criteria have tests. Preloaded chunks are fetched only for pages under a CSP, kept out of
site.scriptsand capped at 20 per audit, with the canonical golden unchanged apart from the new rule's +500 passes. The agent skill needs no change. The maintainer can tick the criteria after merge.nc9 commentedon Oct 8, 2026
Closed: merged in #583 (security/csp-blocks-own-resources). Each acceptance fixture has a named test in the PR, and the rule has its docs page.