蒸馏厂 / 安全
安全中间件和助手
v11.0.0
2024-05-28 09:41 UTC
Requires
- php: >=7.1.3
- ezyang/htmlpurifier: ^4.8
- illuminate/support: ~5.7|~5.8|~6.0|~7.0|~8.0|~9.0|~10.0|~11.0
Requires (Dev)
- fakerphp/faker: ^1.23
- mockery/mockery: ~1.0|^1.2.3|^1.3.1|^1.6
- orchestra/testbench: ~3.7|~3.8|^4.0|^5.0|^6.0|^7.0|^8.0|^9.0
- orchestra/testbench-browser-kit: ~3.7|~3.8|^4.0|^5.0|^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ~7.0|^8.3|^9.3|^10.1|^11.0.1
This package is auto-updated.
Last update: 2024-08-28 10:24:03 UTC
README
安全
该包是否用于从中间件中清理每个数据,或者它可以独立使用以清理字符串。
目录
需求
- Php 7.1.3 或更高版本
安装
在您的 composer.json 中添加
"require": { "distilleries/security": "1.*", }
运行 composer update
。
发布配置
php artisan vendor:publish --provider="Distilleries\Security\SecurityServiceProvider"
配置
return [ 'xss_enable'=> env('SECURITY_XSS_ENABLE',true), 'html_purifier'=> env('SECURITY_HTML_PURIFIER_ENABLE',true) ];
在 kernel 文件中添加中间件。
protected $middleware = [ \Distilleries\Security\Http\Middleware\XSS::class ];
独立使用
您可以直接使用 Security 类来清理数据
清理字符串
$xss = new \Distilleries\Security\Helpers\Security(); $xss->xss_clean('<a href="javascript:aler('test')">Click to alert</a>');
应返回 Click to alert
实体解码
此函数是 html_entity_decode() 的替代品
我们不使用 `html_entity_decode()` 的原因是虽然省略实体末尾的分号在技术上是不正确的,但大多数浏览器仍会正确解释实体。html_entity_decode() 不转换没有分号的实体,因此我们在这里有一个自己的小解决方案。真糟糕。
$xss = new \Distilleries\Security\Helpers\Security(); $xss->entity_decode(<a href="javascript:alert('test')">Test</a>');
应返回 Test
清理文件路径
$xss = new \Distilleries\Security\Helpers\Security(); $xss->sanitize_filename('./../test.jgp',true);
应显示 ./test.jpg 而不是 ./../test.jgp。最后一个参数用于允许或禁止相对路径
$xss = new \Distilleries\Security\Helpers\Security(); $xss->sanitize_filename('./../test.jgp',false);
应显示 test.jpg 而不是 ./../test.jgp。