Content Security Policy (CSP) is a computer security standard that provides an added layer of protection against Cross-Site Scripting (XSS), clickjacking, and other code injection attacks that rely on executing malicious content in the context of a trusted web page.These attacks are used for everything from data theft, to site defacement, to malware distribution.

TYPICAL XSS ATTACK VECTORS

  1. Embedding external resources in the page.
  2. Writing script to the page source.
  3. Modifying the Document Object Model ( DOM ).

SCRIPT TO CHECK XSS VULNERABILITY :-

https://gist.github.com/jonathantneal/656b23d080994df1587f770f61d88c77

UNDERSTANDING CSP

HEADER :

Content-Security-Policy: script-src’self’ ‘unsafe-inline’ ‘unsafe-eval’ [uris]; style-src ‘self’ ‘unsafe-inline’ [uris]; img-src ‘self’ [uris]; frame-src [uris]; font-src ‘self’ [uris]; report-uri [uri]

If we run the above script in a properly configured CSP site , it will throw you the below error, instead of executing the actions.

Untitled