What is a Content Security Policy?
Content Security Policy (CSP) is an added layer of security that helps to detect and mitigate certain types of attacks, including Cross-Site Scripting (XSS) and data injection attacks. These attacks are used for everything from data theft, to site defacement, to malware distribution.
Generally, to enable CSP, you need to configure your web server to return the Content-Security-Policy HTTP header or HTML meta tag. For more details, refer to MDN and OWASP.
On this page, you can find guides on creating Content Security Policies that match your specific needs.
Create a Content Security Policy
In this guide you'll create a simple Content Security Policy template that allows you to generate policies that are ready to be applied to any web application:
![[object Object]](../../img/docs/guides/csp/create_step1_empty.png)
Navigate to Web Security → CSP → Policies and click Create policy.
![[object Object]](../../img/docs/guides/csp/create_step2_form.png)
Enter the policy name, configure directives, and click Save to save the policy.
| Name | |
| Default source (default-src) | |
| Style source (style-src) | |

The new policy appears in the grid.
![[object Object]](../../img/docs/guides/csp/create_step4_copy.png)
Use the Copy context menu button to get different policy representations.
Import a Content Security Policy from URL
In this guide you'll import a Content Security Policy from an external URL:
![[object Object]](../../img/docs/guides/csp/import_url_step1_empty.png)
Navigate to Web Security → CSP → Policies and click Import policy.
![[object Object]](../../img/docs/guides/csp/import_url_step2_modal.png)
Pick URL tab, enter the policy name, target URL, select the policy source, and click Import.
| Policy name | |
| URL | |
| Policy source | |

The new policy appears in the grid.
Import a Content Security Policy from a string
In this guide you'll import a Content Security Policy from a string (serialized policy text):
![[object Object]](../../img/docs/guides/csp/import_string_step1_empty.png)
Navigate to Web Security → CSP → Policies and click Import policy.
![[object Object]](../../img/docs/guides/csp/import_string_step2_modal.png)
Pick Serialized policy tab, enter the policy name, policy string, and click Import.
| Policy name | |
| Serialized policy | |

The new policy appears in the grid.
Share a Content Security Policy
This guide will walk you through sharing a Content Security Policy template publicly, allowing anyone on the internet to view it:
- Navigate to Web Security → CSP → Policies and pick the policy you'd like to share
- Click the policy's Share policy button and toggle Share policy switch to on position
- Once the policy is shared, the dialog will show a Copy link button
- Click the Copy link button to copy a unique shared policy link to your clipboard
- To stop sharing the policy, click the Share policy button again, and switch the Share policy toggle to the off position.
![[object Object]](../../img/docs/guides/csp/share_step1_share.png)
Navigate to Web Security → CSP → Policies, pick the policy you'd like to share, and click Share.
![[object Object]](../../img/docs/guides/csp/share_step2_copy_link.png)
Toggle the Share policy switch to on position, and then click the Copy link button to copy a unique shared policy link to your clipboard.
![[object Object]](../../img/docs/guides/csp/share_step3_unshare.png)
To stop sharing the policy, click the Share policy button again, and switch the Share policy toggle to the off position.
Test a Content Security Policy
In this guide, you will create a Content Security Policy and test it using a custom HTML responder:
![[object Object]](../../img/docs/guides/csp/test_step1_responder_form.png)
Navigate to Webhooks → Responders, click Create responder, and configure it with a simple HTML page that uses eval(). Click Save.
| Name | |
| Path | |
| Method | |
| Body | |

The responder appears in the grid with its unique URL.

Click the URL to open the test page and verify that the Eval button works without restrictions.
![[object Object]](../../img/docs/guides/csp/test_step3_policy_form.png)
Navigate to Web Security → CSP → Policies, click Create policy, and configure it to forbid eval(). Click Save.
| Name | |
| Script source (script-src) | |

The policy appears in the grid.
![[object Object]](../../img/docs/guides/csp/test_step5_copy_meta_tag.png)
Use the Copy context menu button, switch Policy source to HTML meta tag, and copy the generated <meta> tag.
![[object Object]](../../img/docs/guides/csp/test_step6_responder_meta_tag.png)
Navigate back to Webhooks → Responders, edit the CSP Test responder, and paste the <meta> tag inside the <head> of the body. Save and navigate to the responder's URL again - this time, clicking Eval does nothing and a CSP error appears in the browser console.
| Name | |
| Path | |
| Body (updated) | |
Report Content Security Policy violations
In this guide, you will create a Content Security Policy and collect its violation reports using a custom tracking responder:
![[object Object]](../../img/docs/guides/csp/report_step1_reporting_form.png)
Navigate to Webhooks → Responders, click Create responder, enable Advanced mode, and configure a responder to collect CSP violation reports. Click Save.
| Name | |
| Path | |
| Method | |
| Tracking | |

The reporting responder appears in the grid. Copy its URL - you will use it as the report-uri value in the next step.
![[object Object]](../../img/docs/guides/csp/report_step3_policy_form.png)
Navigate to Web Security → CSP → Policies, click Create policy, and configure it with the report-uri directive pointing to the reporting responder URL. Click Save.
| Name | |
| Script source (script-src) | |
| Report URI (report-uri) | |

The policy appears in the grid.
![[object Object]](../../img/docs/guides/csp/report_step5_copy_header.png)
Use the Copy context menu button to view the policy as an HTTP header (enforcing). The generated header includes the report-uri directive with the reporting responder URL.
![[object Object]](../../img/docs/guides/csp/report_step6_eval_form.png)
Navigate back to Webhooks → Responders, click Create responder, and configure a responder that serves an HTML page with eval(). Set its Content-Security-Policy response header to include the policy with the report-uri directive. Click Save.
| Name | |
| Path | |
| Headers | |
| Body | |

Both responders appear in the grid. The CSP Eval Test responder has a unique URL.
![[object Object]](../../img/docs/guides/csp/report_step8_eval_blocked.png)
Click the CSP Eval Test responder URL to open the test page. Click Eval - nothing happens because the Content Security Policy blocks eval(). The browser automatically sends a violation report to the report-uri endpoint.
![[object Object]](../../img/docs/guides/csp/report_step9_violation_report.png)
Go back to the responders grid and expand the CSP Reporting responder. The violation report sent by the browser is now visible in the requests list.