I have a selenium test developed in Selenium IDE
. I have a step in this suite that should type a value in a text field. It fails at that step giving the following error:
18. click on id=firstName Failed:11:12:59
call to eval() blocked by CSP
I have a selenium test developed in Selenium IDE
. I have a step in this suite that should type a value in a text field. It fails at that step giving the following error:
18. click on id=firstName Failed:11:12:59
call to eval() blocked by CSP
Content Security Policy (CSP) acts as a added layer of security that helps to detect and mitigate attacks including Cross Site Scripting (XSS) and data injection attacks. These attacks are primarily used for data theft and distribution of malware.
This error message...
call to eval() blocked by CSP
...implies that the add-on which is being used by the Selenium IDE doesn't include 'unsafe-eval'
in CSP header.
As per the discussion Firefox add-on needs 'unsafe-eval' in CSP header the earlier version of Firefox were not able to detect Ember.js based application if the server sends the Content Security Policy header without 'unsafe-eval'
in the script-src
directive.
This issue was discussed at length within the discussion Convert Firefox add-on to use the Chrome WebExtension and was addressed through a installable WebExtension which can be found here.
As per OP's comment an easier approach would be to tweak the following Key-Value within about:config
which solves the issue:
security.csp.enable off
You can find a relevant discussion in Refused to load the script because it violates the following Content Security Policy directive: script-src error with ChromeDriver Chrome and Selenium
Disabling CSP in about:config
is no longer possible since Firefox 99.
Another solution consists in using a web extension, where you can be more selective on what you enable/disable.
Let say we want to authorize execution of JS (script-src: 'unsafe-eval'
) on https://www.example.org/
:
First install the Firefox extension ModHeader (it is also available on other browsers). Once installed, open the panel:
Click on the +
icon and add a Response header
: as name type Content-Security-Policy
and as value type script-src: 'unsafe-eval'
.
Click on more time on the +
icon and add a Filter
. For the URL pattern
type https:\/\/www.example.org/
.
You may choose precisely what to enable/disable on CSP website.
As has been mentioned, the security.csp.enable
option has been removed as of Firefox 99. While there are third party extensions to allow manipulating the CSP header (as per this answer), be sure that the author is trustworthy.
There is also an official Mozilla extension that can be used too: Laboratory, with an associated Laboratory video tutorial.
Once installed, the basic steps: