dev-master
9999999-devMakes CakePHP 3 CSP supportable by removing inline javascript and inline styles.
MIT
The Requires
- php >=5.4.16
- cakephp/cakephp ~3.0
The Development Requires
Makes CakePHP 3 CSP supportable by removing inline javascript and inline styles.
This plugin does some slight changes in the FormHelper and HtmlHelper, so there won't be any inline script resp. style anymore, so the developer can easily add CSP headers., (*1)
You can install this plugin into your CakePHP application using composer., (*2)
The recommended way to install composer packages is:, (*3)
composer require thefredfox/cakephp-csp
To load this Plugin inside CakePHP:, (*4)
``` php // in bootstrap.php file Plugin::load('Csp');, (*5)
In your layout or your pages, you have to load the css and js files of the csp plugin: ``` php // in your layout/page file $this->Html->css('Csp.csp'); $this->Html->script('Csp.csp'); //this script has to be loaded at the bottom
If you don't use any other FormHelper or HtmlHelper yet, you can easily use the Helpers of this plugin:, (*6)
``` php // in your AppView public function initialize() { $this->loadHelper('Csp.Html'); $this->loadHelper('Csp.Form'); }, (*7)
### Extending third party helpers If you are using another FormHelper or HtmlHelper (e.g. the BootstrapUI helpers), you may use the Traits provided by this plugin in an own extending Helper class: ``` php // in src/View/Helper/FormHelper class FormHelper extends \BootstrapUI\View\Helper\FormHelper { use \Csp\View\Helper\FormHelperTrait; }
If you already extends one of the helpers, you can try to use the Trait like above, but you may want to extend your helper again to not override something., (*8)
``` php // in src/View/Helper/CspFormHelper (or the like), (*9)
class CspFormHelper extends FormHelper {, (*10)
use \Csp\View\Helper\FormHelperTrait;, (*11)
} ```, (*12)
I tried it with my own Helper classes, which extends the BootstrapUI classes. In the HtmlHelper class I already override the link function which also is overridden by the Csp-plugin's HtmlHelper, so I create another CspHtmlHelper class which extends my other HtmlHelper and uses the HtmlHelperTrait by the csp plugin. It works. ;), (*13)
Makes CakePHP 3 CSP supportable by removing inline javascript and inline styles.
MIT