You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The addition of 2FA to the frontend is very welcome, however our Craft CMS breaks when a user visits /login?verify=1, as we have a Content Security Policy defined.
Our Content-Security-Policy header for the page is defined as:
As can be seen from the above, there are a lot of nonces for other inline scripts we use in our templates, which allows these inline scripts to pass CSP.
However, inline scripts added by Craft CMS to the page served at /login?verify=1 (such as those added in /vendor/craftcms/cms/src/templates/_layouts/basecp.twig and /vendor/craftcms/cms/src/web/assets/d3/D3Asset.php) fail CSP because they don't have a nonce:
It could be argued that we resolve this by adding the unsafe-inline keyword to our CSP to allow these scripts -- however doing so only generates the error (in Chrome): Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list.
It would be great if there was a way to support front-end 2FA using a CSP that doesn't allow naked inline scripts.
Steps to reproduce
Define a Content Security Policy, such that a Content-Security-Policy header is served when visiting /login?verify=1. In our case, we use the https://github.com/born05/craft-csp plugin to do this.
Visit /login?verify=1, with the devtools network panel open
Notice the CSP errors generated by the inline scripts added to the page by Craft CMS, which prevent these scripts from loading
As a result we only see a blank (white) page in the browser, with a header with the sitename and the Craft CMS logo
Expected behavior
Using a CSP that prevents unsafe scripts, we can visit /login?verify=1 and be able to perform 2FA
Actual behavior
Using a CSP that prevents unsafe scripts, we visit /login?verify=1 and are not able to perform 2FA, as no elements appear on the page (because the inline scripts that add them are blocked by the CSP).
What happened?
Description
The addition of 2FA to the frontend is very welcome, however our Craft CMS breaks when a user visits
/login?verify=1
, as we have a Content Security Policy defined.Our
Content-Security-Policy
header for the page is defined as:As can be seen from the above, there are a lot of nonces for other inline scripts we use in our templates, which allows these inline scripts to pass CSP.
However, inline scripts added by Craft CMS to the page served at
/login?verify=1
(such as those added in/vendor/craftcms/cms/src/templates/_layouts/basecp.twig
and/vendor/craftcms/cms/src/web/assets/d3/D3Asset.php
) fail CSP because they don't have a nonce:It could be argued that we resolve this by adding the
unsafe-inline
keyword to our CSP to allow these scripts -- however doing so only generates the error (in Chrome):Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list.
It would be great if there was a way to support front-end 2FA using a CSP that doesn't allow naked inline scripts.
Steps to reproduce
Content-Security-Policy
header is served when visiting/login?verify=1
. In our case, we use the https://github.com/born05/craft-csp plugin to do this./login?verify=1
, with the devtools network panel openExpected behavior
Using a CSP that prevents unsafe scripts, we can visit
/login?verify=1
and be able to perform 2FAActual behavior
Using a CSP that prevents unsafe scripts, we visit
/login?verify=1
and are not able to perform 2FA, as no elements appear on the page (because the inline scripts that add them are blocked by the CSP).Craft CMS version
5.6.11
PHP version
8.2
Operating system and version
debian:bullseye-slim
Database type and version
mariadb:10.6
Image driver and version
No response
Installed plugins and versions
From our
composer.json
:The text was updated successfully, but these errors were encountered: