2017 © Pedro Peláez
 

cakephp-plugin cakephp-csp

Makes CakePHP 3 CSP supportable by removing inline javascript and inline styles.

image

thefredfox/cakephp-csp

Makes CakePHP 3 CSP supportable by removing inline javascript and inline styles.

  • Friday, April 15, 2016
  • by TheFRedFox
  • Repository
  • 3 Watchers
  • 3 Stars
  • 442 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 19 % Grown

The README.md

Csp plugin for CakePHP

Description

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)

Installation

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

Configuration

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; }

Extending your own helpers

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)

The Versions

15/04 2016

dev-master

9999999-dev

Makes CakePHP 3 CSP supportable by removing inline javascript and inline styles.

  Sources   Download

MIT

The Requires

 

The Development Requires