Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/amashigeseiji/cake_viewvalue


https://github.com/amashigeseiji/cake_viewvalue

Last synced: 16 days ago
JSON representation

Awesome Lists containing this project

README

        

# ViewValue Plugin for CakePHP
[![Build Status](https://travis-ci.org/amashigeseiji/cake_ViewValue.svg?branch=dev)](https://travis-ci.org/amashigeseiji/cake_ViewValue) [![Coverage Status](https://coveralls.io/repos/amashigeseiji/cake_ViewValue/badge.svg?branch=dev)](https://coveralls.io/r/amashigeseiji/cake_ViewValue?branch=dev)

This plugin let your CakePHP application secure against XSS injection by escaping View variables automatically.

## Requirements

* PHP >= 5.5
* CakePHP >= 2.6

## Setup

In `Config/bootstrap.php`:

```php
#Load ViewValue plugin
CakePlugin::load('ViewValue');
```

and in `Controller/AppController.php`:

```php
public $helpers = array('ViewValue.ViewValue');
```

#### notice

If variables are already escaped by using `h()` helper in your view file, you should remove `h()`.
They might to be cause of double escaping.

## Description

This plugin convert View variable whose type is `String`/`Array`/`Object` into instance of `StringViewValue`/`ArrayViewValue`/`ObjectViewValue`.
They act as their original variable type.
If need arise, you can get raw value by calling `raw()` method in view file.

## Sample code

`StringViewValue` act as string.
```php
#Controller/SampleController.php
public function index() {
$this->set('xssstr', 'alert(0)');
}
```
```html


raw(); ?>
```

and `ArrayViewValue` act as array.
```php
#Controller/SampleController.php
public function index() {
$this->set('arr', array('alert(0)', 'hoge', array('fuga', array('hoge', 'fuga'))));
}
```
```html



```