Repository navigation
Closed
New rule: security/csp-violations - report what the browser actually blocked during rendered crawls#425
Feature
Copy link
Labels
P2hamsterwheelenhancementNew feature or requestrulespackages/rules — audit rule definitionssecuritySecurity hardeningsize: Lhamsterwheel
Description
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. CSPscript-srcdidn'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/collectandstats.g.doubleclick.net/g/collect.connect-srconly allowedwww.google-analytics.comandregion1.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/cspgrades the header itself (unsafe-inline, wildcard and so on). Its findings were identical for the broken and the fixed policy.analytics/gtm-presentpassed, 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.
- Renderer: before any page script runs (as an init script), register a
securitypolicyviolationlistener ondocument. Also record failed requests and page errors. Keep listening about 3–5s afterload, 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
securitypolicyviolationlistener caught the blocks.
- A console listener alone is not enough. In testing, a CLI console reader showed nothing on the broken page, and only the
- 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.
- 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-srcomits the host of a script injected after load → one violation reported, naming the host andscript-src-elem. - Fixture: an Ads-linked gtag page with
connect-srclimited towww.google-analytics.com→ error listing the blocked/g/collectendpoints. - 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-srcomits the host of a script injected after load produces onesecurity/csp-violationsfinding naming the blocked host andscript-src-elem - Fixture: an Ads-linked gtag page with
connect-srclimited towww.google-analytics.comproduces an error listing the blocked/g/collectendpoints, 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-violationswith 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 underdocs/rules/security/
Activity
nc9 commentedon Oct 1, 2026
Static companion rule (no render): #426. Related false positive in security/csp: #427.
feat(rules): security/csp-violations from rendered-crawl browser even…
feat(rules): security/csp-violations from rendered-crawl browser even…
fix(core-contracts,rules): browser events text goes through stripUnsa…
fix(core-contracts): a blockedUri of another scheme keeps its scheme …
fix(core-contracts): blockedUri of a rejected URL is cut at its autho…
feat(rules): security/csp-violations from rendered-crawl browser even…
fix(core-contracts,rules): browser events text goes through stripUnsa…
fix(core-contracts): a blockedUri of another scheme keeps its scheme …
fix(core-contracts): blockedUri of a rejected URL is cut at its autho…
feat(rules): security/csp-violations from rendered-crawl browser even…
fix(core-contracts,rules): browser events text goes through stripUnsa…
fix(core-contracts): a blockedUri of another scheme keeps its scheme …
fix(core-contracts): blockedUri of a rejected URL is cut at its autho…
fix(rules,core-contracts): csp-violations parked as ingestion-only; d…
test(core-contracts): build userinfo fixtures from parts for the secr…
feat(rules): security/csp-violations reports what the browser blocked…