munichresearch / yii2_cached_purifier
将清洗后的内容缓存以提高性能
dev-master
2018-03-14 20:10 UTC
Requires
- yiisoft/yii2: >2.0.0
This package is not auto-updated.
Last update: 2024-09-20 20:05:54 UTC
README
Yii2 组件,将 HTML Purifier 的结果缓存到实现 yii\caching\CacheInterface 的缓存中。这将从字符串中移除恶意代码(XSS),并使其符合标准。更多信息请参见 Yii2 安全最佳实践
要求
- "yiisoft/yii2": ">2.0.0"
- "ezyang/htmlpurifier": "~4.9.3"
- "php": ">=5.2"
安装
通过 Composer
$ composer require linuskohl/yii2_cached_purifier dev-master
或添加
"linuskohl/yii2_cached_purifier": "dev-master"
到您的 composer.json 文件的 require 部分。
配置
要使用此组件,只需在您的应用程序配置中添加以下代码
return [ //.... 'components' => [ 'cache' => [ 'class' => 'yii\redis\Cache', 'redis' => [ 'hostname' => 'localhost', 'port' => 6379, 'database' => 0, ] ], 'cached_purifier' => [ 'class' => '\munichresearch\yii2_cached_purifier\CachedPurifier', 'cache' => 'redis', // name of the cache component 'cache_duration' => 0, // Duration to store the secured strings. Set it to 0 to disable expiration */ 'key_prefix' => 'secured_strings::', // Prefix for the cache keys 'key_hash' => 'sha512' // Hash used to create key ], ], ];
用法
<?= \Yii::$app->cached_purifier->purify($insecure_string) ?>
许可协议
MIT 许可协议 (MIT)。请参阅 许可文件 了解更多信息。