-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add documentation for
stripCspDirectives
and CSP information
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: Content Security Policy | ||
e2eSpecific: true | ||
--- | ||
|
||
Content Security Policy (CSP) is a browser security feature that allows you to | ||
restrict the resources that can be loaded into your application. This can be | ||
problematic for Cypress, because it needs to inject JavaScript into your | ||
application in order to run tests and interact with the DOM. This page describes | ||
how Cypress handles CSP and how to configure it to work with your application. | ||
|
||
There are two ways to implement CSP: | ||
|
||
- [Meta tag](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta#http-equiv) | ||
- [HTTP header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy) | ||
|
||
The `<meta>` tag implementation is fully supported by Cypress without any | ||
configuration required. This is because Cypress loads the necessary `<script>` | ||
tags into your application before any `<meta>` tag is parsed. This prevents any | ||
CSP directives from being applied to the script loaded by Cypress. | ||
|
||
The second implementation requires you to configure Cypress to allow the headers | ||
to be sent to your application. By default, Cypress will remove any CSP headers | ||
from the response before it is sent to the browser. This is done to prevent | ||
Cypress from being blocked by the browser's CSP implementation. | ||
|
||
For most application tests, this should not cause any issues. However, if you | ||
are testing your application's CSP implementation, you will need to configure | ||
Cypress to allow the headers to be sent to the browser. You can do this by | ||
setting the | ||
[`stripCspDirectives`](/guides/references/configuration#stripCspDirectives) | ||
configuration option to `false`. | ||
|
||
For more information on CSP, see the | ||
[Content Security Policy](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) | ||
documentation on MDN. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters