amashigeseiji/viewvalue 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

amashigeseiji/viewvalue

最新稳定版本:0.9.0

Composer 安装命令:

composer require amashigeseiji/viewvalue

包简介

ViewValue plugin for CakePHP

README 文档

README

Build Status Coverage Status

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:

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

and in Controller/AppController.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.

#Controller/SampleController.php
public function index() {
	$this->set('xssstr', '<script>alert(0)</script>');
}
<!-- View/Smaple/index.ctp -->
<?php echo $xssstr; ?> <!-- &lt;script&gt;alert(0)&lt;/script&gt; (display correctly in browser) -->
<?php echo $xssstr->raw(); ?> <!-- <script>alert(0)</script> (script is triggered) -->

and ArrayViewValue act as array.

#Controller/SampleController.php
public function index() {
	$this->set('arr', array('<script>alert(0)</script>', 'hoge', array('fuga', array('hoge', 'fuga'))));
}
<!-- View/Smaple/index.ctp -->
<?php echo $arr[0]; ?> <!-- &lt;script&gt;alert(0)&lt;/script&gt; (display correctly in browser) -->
<?php var_dump($arr instanceof ArrayViewValue) ?> <!-- true -->
<?php var_dump($arr[0] instanceof StringViewValue) ?> <!-- true -->
<!-- `$arr[0]` is converted to `StringViewValue`. -->
<?php var_dump($arr[2][1] instanceof ArrayViewValue) ?> <!-- true -->
<!-- The value of any hierarchy will be converted into BaseViewValue inheritance. -->

<!-- off course you can use foreach -->
<?php
foreach ($arr as $val) {
	echo $val;
}
?>

统计信息

  • 总下载量: 46
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-06-17