Skip to content

New rule: security/csp-violations - report what the browser actually blocked during rendered crawls #425

Description

@nc9

Problem

A production site's Content-Security-Policy blocked resources the site depended on, for about three months, and no squirrel audit noticed. Over that window, 8 audits ran, both HTTP and cloud-rendered:

  • Booking widget never loaded. A third-party booking widget is injected as a <script> after hydration. CSP script-src didn't allow its host, so the booking page rendered an empty container.
  • Every GA4 hit was blocked. The property's Google tag is linked to Google Ads, so it posts to analytics.google.com/g/collect, www.google.com/g/collect and stats.g.doubleclick.net/g/collect. connect-src only allowed www.google-analytics.com and region1.google-analytics.com.
  • The Google Ads script was blocked: googleads.g.doubleclick.net/pagead/viewthroughconversion/....

The browser reported every one of these as a securitypolicyviolation: 8 on the booking page alone. The page itself returned 200 and looked normal.

Why squirrel missed it:

  • The rendered crawl returns HTML and headers only. Nothing collects CSP violations, failed requests or page errors.
  • security/csp grades the header itself (unsafe-inline, wildcard and so on). Its findings were identical for the broken and the fixed policy.
  • analytics/gtm-present passed, because it only checks that the tag is in the HTML.
  • The blocked Ads script only showed up as a security/sri "missing integrity" finding.

Proposal

New rule security/csp-violations, for rendered crawls.

  1. Renderer: before any page script runs (as an init script), register a securitypolicyviolation listener on document. Also record failed requests and page errors. Keep listening about 3–5s after load, because embeds and analytics hits often fire after hydration. Attach { violatedDirective, effectiveDirective, blockedURI, sourceFile, lineNumber }[], the failed requests and the page errors to the page result.
    • A console listener alone is not enough. In testing, a CLI console reader showed nothing on the broken page, and only the securitypolicyviolation listener caught the blocks.
  2. Rule: report per page, grouped by blocked host and directive.
    • Error when the blocked URL belongs to a known form/booking, analytics, ads, payments or captcha vendor (reuse tech detection).
    • Warn otherwise.
    • Include the directive to change and the host to add.
  3. Follow-on, same data: "analytics detected but no hit left the page". Tech detection finds GA4, GTM, PostHog etc., but the request log has no successful collect/ingest request.

Acceptance

  • Fixture: a page whose CSP script-src omits the host of a script injected after load → one violation reported, naming the host and script-src-elem.
  • Fixture: an Ads-linked gtag page with connect-src limited to www.google-analytics.com → error listing the blocked /g/collect endpoints.
  • Same pages with a corrected policy → pass.
  • HTTP-only (non-rendered) audits skip the rule with a clear reason.

Notes

  • Cost: render only. No extra page loads, just the listeners plus a short post-load wait.
  • False-positive risk: low. It reports the browser's own verdict.
  • Needs renderer support: the rendered page result currently carries HTML + headers only.
  • Complements the static check in the companion issue (CSP vs page resources), which needs no render.

Acceptance Criteria

  • Fixture: a page whose CSP script-src omits the host of a script injected after load produces one security/csp-violations finding naming the blocked host and script-src-elem
  • Fixture: an Ads-linked gtag page with connect-src limited to www.google-analytics.com produces an error listing the blocked /g/collect endpoints, at error severity because the vendor is an analytics/ads vendor
  • The same fixtures with a corrected policy pass
  • HTTP-only (non-rendered) audits skip security/csp-violations with a clear skip reason
  • Rendered page results carry the collected CSP violations (directive, blocked URI, source file, line), failed requests and page errors, including those that fire a few seconds after load, and the rule has a docs page under docs/rules/security/

Activity

  1. added
    enhancement
    P1
    size: L
    rules
    security
    on Oct 1, 2026
  2. nc9 commented on Oct 1, 2026

    @nc9
    ContributorAuthor

    Static companion rule (no render): #426. Related false positive in security/csp: #427.

  3. added
    P2
    and removed
    P1
    on Oct 7, 2026
  4. added theissue type on Oct 28, 2026
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: L

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions