

The behavior was allowed, and a CSP report was sent. In Firefox you might see messages like this in the Web Developer Tools: Content Security Policy: A violation occurred for a report-only CSP policy ("An attempt to execute inline scripts has been blocked").

In Chrome when a Content Security Policy Script Violation happens you get a message like this one in the Chrome Developer Tools: Refused to load the script ' script-uri' because it violates the following Content Security Policy directive: " your CSP directive". default-src 'none' script-src 'self' connect-src 'self' img-src 'self' style-src 'self' base-uri 'self' form-action 'self' It is a good starting point for many sites. This policy allows images, scripts, AJAX, form actions, and CSS from the same origin, and does not allow any other resources to load (eg object, frame, media, etc).

Here a few common scenarios for content security policies: Allow everything but only from the same origin default-src 'self' Only Allow Scripts from the same origin script-src 'self' Allow Google Analytics, Google AJAX CDN and Same Origin script-src 'self' Starter Policy Does not apply to javascript: or inline CSP Level 3 Script-src 'unsafe-hashes' 'sha256-abc.'Īllows you to enable scripts in event handlers (eg onclick). CSP Level 2Įnables an allowed script to load additional scripts via non-"parser-inserted" script elements (for example document.createElement('script') is allowed). The nonce should be a secure random string, and should not be reused. CSP Level 2Īllows an inline script or CSS to execute if the script (eg: ) tag contains a nonce attribute matching the nonce specifed in the CSP header. Currently supports SHA256, SHA384 or SHA512.
#Modern meta code
Prevents loading resources from any source.Īllows loading resources from the same origin (same scheme, host and port).Īllows loading resources via the data scheme (eg Base64 encoded images).Īllows loading resources from the specified domain name.Īllows loading resources from any subdomain under .Īllows loading resources only over HTTPS matching the given domain.Īllows loading resources only over HTTPS on any domain.Īllows use of inline source elements such as style attribute, onclick, or script tag bodies (depends on the context of the source it is applied to) and javascript: URIsĪllows unsafe dynamic code evaluation such as JavaScript eval()Īllows an inline script or CSS to execute if its hash matches the specified hash in the header. Wildcard, allows any URL except data: blob: filesystem: schemes. Multiple source list values can be space separated with the exception of 'none' which should be the only value. Implementation Status Example navigate-to Policy navigate-to CSP Level 3Īll of the directives that end with -src support similar values known as a source list. If form-action is present then this directive is ignored for form submissions. For example when a link is clicked, a form is submitted, or window.location is invoked. Restricts the URLs that the document may navigate to by any means.
