Skip to content

New rule: security/csp-blocks-own-resources - flag a CSP that blocks the page's own scripts, frames and analytics endpoints #426

Closed

Description

@nc9

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:

  1. Parse each page's CSP. Reuse the parser in packages/rules/src/security/csp.ts, but note that rule only reads ctx.site.pages[0]. Policies can differ per route.

  2. 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.ts follows plain same-domain <script src> only.

  3. Match each URL against its directive (script-src(-elem), frame-src/child-src, style-src, img-src, falling back to default-src). Use real CSP source matching: schemes, 'self', host wildcards (*.example.com does not match example.com), ports, paths.

  4. 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; frame td.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.

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 listing analytics.google.com, www.google.com and stats.g.doubleclick.net for connect-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.com in script-src with a script from cdn.example.com → pass; with a script from example.com → finding.
  • No CSP header → rule passes (missing CSP is security/csp's job).

Notes

Acceptance Criteria

  • Fixture: gtag for an Ads-linked property plus connect-src 'self' https://www.google-analytics.com produces an error listing analytics.google.com, www.google.com and stats.g.doubleclick.net for connect-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.com in script-src passes for a script from cdn.example.com and produces a finding for a script from example.com
  • A page with no CSP header passes security/csp-blocks-own-resources (missing CSP stays with security/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

  1. added
    enhancement
    P1
    size: M
    rules
    security
    P2
    and removed
    P1
    on Oct 1, 2026
  2. nc9 commented on Oct 8, 2026

    @nc9
    ContributorAuthor

    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.

  3. nc9 commented on Oct 8, 2026

    @nc9
    ContributorAuthor

    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.scripts and 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.

  4. nc9 commented on Oct 8, 2026

    @nc9
    ContributorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2enhancementrulessecuritysize: M

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions