
A wrapper of voku/anti-xss for Laravel
Laravel Security 由 Graham Campbell 创建并维护,它是一个面向 Laravel 的 voku/anti-xss 封装,基于 graham-campbell/security-core。欢迎查看更新日志、发布版本、安全策略、许可协议、行为准则和贡献指南。

本版本要求 PHP 8.0-8.3,并支持 Laravel 9-11。
要获取最新版本,只需使用 Composer 引入该项目即可:
$ composer require "graham-campbell/security:^11.2"
安装完成后,如果你未使用自动包发现(automatic package discovery),则需要在 config/app.php 中注册 GrahamCampbell\Security\SecurityServiceProvider 服务提供者。
你也可以选择性地为我们的门面(facade)设置别名:
'Security' => GrahamCampbell\Security\Facades\Security::class,
Laravel Security 支持可选配置。
要开始使用,你需要发布所有供应商资源(vendor assets):
$ php artisan vendor:publish
这将在你的应用中创建 config/security.php 文件,你可以修改它以设置自己的配置。同时,请务必在版本升级之间检查此包中原配置文件的变更。
共有两个配置选项:
该选项('evil')定义了恶意属性和标签,这些内容将始终从输入中被剔除。
该选项('replacement')定义了替换字符串,用于替代因存在 XSS 而被移除的字符串部分。
这是最值得关注的类。它被绑定到 IoC 容器中,名称为 'security',可通过 Facades\Security 门面进行访问。其中有一个值得关注的公共方法。
'clean' 方法将解析字符串,并尽最大努力移除其中的 XSS 漏洞。
该门面会将静态方法调用动态转发给 IoC 容器中的 'security' 对象,该对象默认为 Security 类。
该类不包含值得关注的公共方法。该类应添加到 config/app.php 的 providers 数组中,并会设置 IoC 绑定。
你可以在 Laravel Binput 中查看实现示例。
如果你在此包中发现安全漏洞,请发送电子邮件至 [email protected]。所有安全漏洞都将得到及时处理。你可以在此查看我们的完整安全策略。
Laravel Security 采用 The MIT License (MIT) 许可协议。
作为 Tidelift 订阅的一部分提供
graham-campbell/security 的维护者与数千个其他软件包的维护者正在与 Tidelift 合作,为你构建应用所使用的开源依赖提供商业支持与维护。在为你所使用的确切依赖的维护者付费的同时,节省时间、降低风险并改善代码健康状况。了解更多。
| Security | L5.5 | L5.6 | L5.7 | L5.8 | L6 | L7 | L8 | L9 | L10 | L11 |
|---|
| 5.1 | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ |
| 6.2 | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ |
| 7.1 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| 8.0 | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ |
| 9.1 | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ |
| 10.0 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ❌ |
| 11.2 | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ |