New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any form of CSP will break the admin plugin #385

laurensvanochten opened this Issue Jan 8, 2016 · 2 comments


None yet
3 participants

laurensvanochten commented Jan 8, 2016

When deploying CSP in the HTTP headers through the .htaccess file it will break the admin plugin, even with 'unsafe-eval' enabled. Unsure what the exact root cause is. From the firebug console it seems the CSP policy is blocking the loading of a resource based on the script-src policy, which unless the admin plugin requires external scripts should be fine (doesn't seem that the admin plugin actually calls an external script as far as I can judge).

# CSP Apache Header set Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-eval'; style-src 'self'; media-src 'self';"

@rhukster rhukster added the bug label Jan 8, 2016


This comment has been minimized.


rhukster commented Jan 8, 2016

Did you look at the new session options? Maybe they will help with this?


This comment has been minimized.

kyodev commented Oct 29, 2016

I'm new with Grav. I started easily but now, when I want to optimize, I can not use anymore this plugin with CSP.
In Google Chrome console, I see clearly that the problem is 2 inline scripts. For security reasons, inline scripts are unsafe. I can't solve that with htaccess only for the admin plugin.
My .htaccess:

<IfModule mod_headers.c>
Header set Content-Security-Policy: "script-src 'self' https://*; report-uri /csp-report.php"

Ideally, I you can externalize the javascript

<script src="/user/plugins/admin/themes/grav/js/acript.js" type="text/javascript">

it would be great,
I've changed a troublesome script but for your plugin, I don't know how build a external javascript file with twig.
You can also send, with php, a header like

//horrible but urgently workaround
header("Content-Security-Policy : default-src 'self' 'unsafe-inline';");
//or better with a nonce declaration
header("Content-Security-Policy : default-src 'self' 'nonce-cf22c45833a1453b77429cd9e63993da';");
// with script declaration:
<script nonce=cf22c45833a1453b77429cd9e63993da>

A good introduction: content-security-policy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment