squirrelscan
GitHub

Content-Security-Policy: what to set and how to check it

A missing CSP, a report-only policy or an unsafe-inline script-src leaves XSS unmitigated. squirrel parses the header and names each gap.

What a Content Security Policy is

Content-Security-Policy is a response header that lists, per resource type, which origins a page is allowed to load from and whether inline code may run. The browser enforces it and blocks anything outside the policy. Its main job is to contain cross-site scripting: an injected <script> cannot execute if the policy has no matching source.

A policy is only worth what its script-src says. 'unsafe-inline' re-permits exactly the injected code CSP exists to stop, unless the same source list also carries a nonce or a hash, in which case browsers ignore it. A wildcard source lets any host serve executable code. Content-Security-Policy-Report-Only sends violation reports without blocking anything, which is the right way to develop a policy and the wrong way to ship one.

What squirrel checks

The rule reads the response headers of the first crawled page and can emit several checks:

  • csp skipped when the crawl produced no pages. Message: No pages to check.

  • csp-missing warns when neither Content-Security-Policy nor Content-Security-Policy-Report-Only is present. Message: No Content-Security-Policy header. No further checks run.

  • csp-report-only warns when only the report-only header is set. Message: CSP in report-only mode (not enforced).

  • csp-present passes when the enforcing header is set. Message: CSP header present and enforced, with the first 100 characters of the policy as the value.

  • csp-no-script-control warns when the policy declares neither script-src nor default-src. script-src-elem and script-src-attr alone do not count: each covers one surface (script elements, inline event handlers) and leaves eval() and the other surface unrestricted. Message: CSP has no script-src or default-src directive.

  • csp-unsafe-scripts warns when the effective script source lists 'unsafe-eval', or lists 'unsafe-inline' with no nonce, hash or 'strict-dynamic' beside it (see below). Message: CSP allows <keywords>, where <keywords> is 'unsafe-inline', 'unsafe-eval' or both joined with and.

  • csp-wildcard warns when that same source list contains a source whose host is a bare *, such as *, https://* or *:443, which lets scripts load from any host, and the list has no 'strict-dynamic'. A host wildcard such as https://*.example.com is scoped to one domain’s subdomains and does not trigger it. Message: CSP script-src allows wildcard (*).

  • csp-no-frame-ancestors reports info when frame-ancestors is absent and no X-Frame-Options header is set either. Message: CSP missing frame-ancestors directive.

  • csp-no-object-src reports info when neither object-src nor default-src is declared. Message: CSP missing object-src directive.

  • csp-self-proxy-script reports info when 'self' is in the effective script list for script elements (script-src-elem, else script-src, else default-src), the policy is enforced, and a crawled script is loaded from a known first-party proxy path. It stays silent when 'strict-dynamic' is in that list (browsers ignore 'self' then) and when several comma-joined policies are set (they intersect, so 'self' may be blocked by another one). It reads only the first-party scripts the crawl fetched, up to the crawl’s script fetch limit, so a proxy script past that limit is not seen. A hit is a possible proxy path, not a finding: /stats and /ingest are also common ordinary app routes. Message: CSP 'self' allows a possible first-party proxy path <paths>.

  • csp-connect-unrestricted warns when the page loads a third-party script and the enforced policy lets script send data to any host: no connect-src and no default-src, or the one browsers read (connect-src, else default-src) holds *, a host of * such as https://*, or a network scheme-only source (https:, http:, wss:, ws:). A list of hosts, 'self' or 'none' does not trigger it, and neither do data: or blob:, which reach no host. Message: Script on the page can send data to any host.

  • csp-strict-dynamic-third-party reports info when the page loads a third-party script and the enforced policy’s script list for elements (script-src-elem, else script-src, else default-src) holds 'strict-dynamic'. Message: CSP 'strict-dynamic' also trusts every script a third-party script inserts.

  • csp-no-reporting reports info when the page loads a third-party script and the enforced policy has neither report-to nor report-uri. Message: CSP violations are not being collected.

On a targeted audit (--target-url) the rule reads each listed page that answered with a status under 400 instead, and each check names the pages it speaks for in pages (one row for the pages with the same result).

Every check carries structured evidence beside its message (#1735): pages lists the page the header was read from (the first crawled page; on a targeted audit, every listed page with that result), and details holds pageUrl (left out of a row for several pages) and header (content-security-policy, or content-security-policy-report-only when only that one is set). csp-unsafe-scripts and csp-wildcard add directive, the directive browsers read the weak source from (script-src-elem, script-src-attr, script-src, or default-src when neither script directive is set), and its value (cut to 300 characters), plus directives, every directive carrying a weak source with its sources. csp-self-proxy-script adds the proxy paths. The three third-party checks add thirdPartyHosts, the third-party script hosts the page loads (up to 20), and csp-connect-unrestricted adds the directive and value that leave connections open when there is one. When the page loads a third-party script, csp-unsafe-scripts for 'unsafe-eval' adds thirdPartyHosts too, and its value says that a compromised vendor script could run code it builds from a string. A report, an agent and the cloud issue view read the page and the directive from these fields instead of parsing the message.

The effective script source is script-src when it is present and non-empty, otherwise default-src. script-src-elem overrides it for <script> elements, so 'unsafe-inline' and wildcard sources are judged on script-src-elem when it is set, in both directions: a strict script-src-elem clears a loose script-src, and a loose one is flagged next to a strict script-src. Inline event handlers such as onerror= are not script elements: 'unsafe-inline' is also judged on script-src-attr, which falls back to script-src, then default-src, and never to script-src-elem, so a strict script-src-elem does not clear an 'unsafe-inline' that still allows handlers through script-src unless script-src-attr is set as well. 'unsafe-eval' is still read from script-src or default-src, because no element or attribute directive controls eval(). Its sources are compared as whole tokens, ignoring case, the way browsers read them: 'UNSAFE-INLINE' is 'unsafe-inline', and a host that merely contains one of these strings is not a match. A header that carries several comma-separated policies is read as one list. Severity is warning and the scope is site-wide.

Some sources are ignored by browsers when the same list carries others (CSP Level 3), and squirrel ignores them too:

  • A nonce ('nonce-…') or a hash ('sha256-…', 'sha384-…', 'sha512-…') makes 'unsafe-inline' ignored.
  • 'strict-dynamic' makes 'unsafe-inline', 'self' and every host and scheme source ignored, a bare * included.
  • Neither changes 'unsafe-eval', which always warns.

So a strict policy of the shape Google recommends, such as script-src 'nonce-r4nd0m' 'strict-dynamic' https: 'unsafe-inline', passes: https: and 'unsafe-inline' are only there as a fallback for browsers older than CSP Level 3. Only the directive’s own list counts, so a nonce after a comma, in a second policy’s other directive, does not switch a warning off.

Third-party scripts

A vendor script runs with the page’s full authority, and if the vendor is compromised, its own host serves the attacker’s code. Allowing that host in script-src cannot stop it. What still limits the damage is whether the stolen data can leave and whether anyone hears about it. In the November 2026 Optimizely incident analysed by Report URI, sites whose connect-src listed only the hosts they needed ran the payload but blocked the data theft, 'strict-dynamic' let the payload through, and 'unsafe-eval' let an inline copy of it run.

So when the judged page loads at least one third-party script, squirrel reads the enforced policy for those gaps: csp-connect-unrestricted, csp-strict-dynamic-third-party, csp-no-reporting, and the vendor context on 'unsafe-eval'. A page that loads no third-party script gets none of them, and neither does a report-only policy (csp-report-only already says nothing is enforced). When the header carries several comma-separated policies, each is read on its own, because the browser enforces all of them: one that restricts connections restricts them, and 'strict-dynamic' counts only when every policy that controls scripts has it.

Limits:

  • A third-party script is a <script src> in the fetched HTML, outside <noscript>, on a host outside the page’s own domain. The own domain is the last two labels of the page host, or three when they look like a country suffix such as co.uk, so static.example.com is first party on www.example.com. No public suffix list is loaded, so the guess errs toward first party: a script from another tenant of a shared hosting domain (two vercel.app sites, say) is not counted.
  • squirrel reads the header and the fetched HTML. It does not execute the page, so a script that a tag manager or another script inserts at run time is not seen, and a page whose only vendor code arrives that way gets none of these checks.
  • 'strict-dynamic' is still the right choice for many sites, which is why its check is info: it says what the policy trusts, so you can decide whether you trust everything your vendors load.

First-party proxy paths

A policy such as default-src 'self'; script-src 'self' looks tight, but a same-origin path can be a rewrite that serves third-party code, so 'self' trusts that code too. The header alone cannot show it, so squirrel compares the crawled script URLs of the site with a fixed list of path prefixes that analytics products commonly use for such rewrites. No request is made. A prefix matches whole path segments, so /ingest/static/array.js matches and /ingestor.js does not. A script on another origin never matches.

Path prefixTypical use
/_vercel/insightsVercel Web Analytics script
/_vercel/speed-insightsVercel Speed Insights script
/ingestAnalytics reverse proxy (for example a PostHog rewrite)
/statsAnalytics reverse proxy (for example a Plausible or Umami rewrite)
/plausiblePlausible proxy
/umamiUmami proxy

The check is info, not a failure: a proxy is often a deliberate way to avoid ad blockers. What to do: confirm you trust the code behind the path and that the upstream is pinned to a version you review. Where you control the page, serve such scripts with a nonce or hash and drop 'self' for scripts, so a compromised or changed proxy target is not allowed by default.

How to fix it

Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-r4nd0m'; object-src 'none'; frame-ancestors 'self'

Set the header at the edge or in the application response, and generate a fresh nonce per response for the inline scripts you cannot remove. Develop the policy under Content-Security-Policy-Report-Only first, then move the same value to the enforcing header.

A policy that legitimately allows a wildcard for images or fonts is not flagged. Only the script source list is checked for *, 'unsafe-inline' and 'unsafe-eval', and the connect source list for * and scheme-only sources, the latter only on a page that loads a third-party script.

On such a page, also set connect-src to the hosts the page needs to reach and add a reporting endpoint, so a compromised vendor script cannot send data out and its blocked attempts reach you:

Content-Security-Policy: default-src 'self'; script-src 'self' https://cdn.vendor.example; connect-src 'self' https://api.example.com; report-to csp-endpoint
Reporting-Endpoints: csp-endpoint="https://example.com/csp-reports"
Rule IDsecurity/csp
CategorySecurity
ScopeSite-wide
Severitywarning
Weight6/10

Enable / disable

Disable this rule

[rules]
disable = ["security/csp"]

Disable all Security rules

[rules]
disable = ["security/*"]

Enable only this rule

[rules]
enable = ["security/csp"]

enable replaces the default ["*"], so this is the only rule selected. Leave disable out: a rule that matches any disable pattern is skipped even when enable names it. Only an enabled setting under a rule’s own [rule_options] table overrides both lists.

Check names by outcome

Each check name this rule can emit, by what it means to a tool comparing two audits. A problem check is a finding. A clean check says the rule ran over what it covers and found nothing; it clears the problem checks listed beside it, so a finding is fixed when the rule ran over the same scope and a clean check took its place. A not checked check says the rule did not evaluate, and never clears a finding.

Check nameOutcomeClears
csp-missingProblem
csp-report-onlyProblem
csp-no-script-controlProblem
csp-unsafe-scriptsProblem
csp-wildcardProblem
csp-self-proxy-scriptProblem
csp-no-frame-ancestorsProblem
csp-no-object-srcProblem
csp-connect-unrestrictedProblem
csp-strict-dynamic-third-partyProblem
csp-no-reportingProblem
csp-presentCleancsp-missing, csp-report-only
cspNot checked

Security findings ship in every audit next to the SEO, performance and agent experience rules. See Website security scan with AI for how an agent works through a report.

Glossary: Content Security Policy (CSP), Security headers, X-Frame-Options.

References

Check your site

Run squirrel audit https://nutshop.squirrelscan.com and open the Security section of the report. The policy is parsed and each weak directive is named. Signed-out local audits need no account and cost nothing. Signed-in audits spend credits.

Type to search…

↑↓ navigate↵ openesc close