定制 amashigeseiji/viewvalue 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱: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
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固