CSP Builder

Build a Content-Security-Policy header, or paste one to see what it allows and where it is weak.

everything that is fetched and has no directive of its own
scripts, inline and loaded
stylesheets and inline styles
images, favicons and CSS background images
fetch(), XMLHttpRequest, WebSocket and EventSource
<object>, <embed> and <applet>
the URLs a <base> element may point at
where forms may submit to
who may frame this page
http:// subresources, which it asks for over https://

A nonce has to be fresh for every response, so 'nonce-REPLACE_ME' is a placeholder: your server fills it in and puts the same value in the <script nonce=…> tag.

1 finding worst low

10 directives

Content-Security-Policy

default-src 'none'; script-src 'nonce-REPLACE_ME' 'strict-dynamic'; style-src 'self'; img-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'none'; form-action 'self'; frame-ancestors 'none'; upgrade-insecure-requests

The same policy as a meta tag

<meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'nonce-REPLACE_ME' 'strict-dynamic'; style-src 'self'; img-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'none'; form-action 'self'; upgrade-insecure-requests">

A meta tag only works in HTML, has to be in the <head>, and is read once: a header can be changed per response.

Findings · worst low

  • low A <meta> tag ignores frame-ancestors. If this policy goes into HTML, that directive is doing nothing there: send it as a header.

Every directive, in plain words

DirectiveWhat it governsSources
default-srceverything that is fetched and has no directive of its own
  • 'none' nothing of this kind may load
script-src
→ default-src
scripts, inline and loaded
  • 'nonce-REPLACE_ME' the script carrying this nonce may run
  • 'strict-dynamic' only scripts this document trusts may add more scripts
style-src
→ default-src
stylesheets and inline styles
  • 'self' this origin only
img-src
→ default-src
images, favicons and CSS background images
  • 'self' this origin only
connect-src
→ default-src
fetch(), XMLHttpRequest, WebSocket and EventSource
  • 'self' this origin only
object-src
→ default-src
<object>, <embed> and <applet>
  • 'none' nothing of this kind may load
base-urithe URLs a <base> element may point at
  • 'none' nothing of this kind may load
form-actionwhere forms may submit to
  • 'self' this origin only
frame-ancestorswho may frame this page
  • 'none' nothing of this kind may load
upgrade-insecure-requestshttp:// subresources, which it asks for over https://no sources: the directive takes none, or an empty list blocks everything

Checked against CSP Level 3: every directive, every source keyword, and the fallback chain that carries a directive to default-src. Nothing is uploaded, and no request is made to the site whose policy you paste.

More in the yard