zae / csp-reporting
CSP 报告
1.0.0
2023-04-20 09:34 UTC
Requires
- php: >= 8.0
- ext-json: *
- nyholm/psr7: ^1.2
- psr/log: ^1.0 || ^2.0 || ^3.0
- symfony/psr-http-message-bridge: ^2.0
Requires (Dev)
- bugsnag/bugsnag: ^3.0
- craftcms/cms: ^3.0
- illuminate/cache: ^8.0 || ^9.0 || ^10.0
- illuminate/http: ^8.0 || ^9.0 || ^10.0
- infection/infection: >= 0.17
- mockery/mockery: ^1.3
- orchestra/testbench: ^6.0 || ^7.0 || ^8.0
- phpunit/phpunit: ^8.3 || ^9.0
- vimeo/psalm: ^5.0
Suggests
- bugsnag/bugsnag: If you want to use the BugsnagPersister
- illuminate/cache: If you want to use the CacheRateLimiter
- zae/content-security-policy: Add CSP headers to your responses
- zae/strict-transport-security: Add HSTS header to your responses
README
捕捉用户产生的策略违规并存储在某个地方
安装
通过 Composer
$ composer require zae/csp-reporting
使用方法
配置 csp 报告发送到 /csp-report
。
Laravel
使用 artisan vendor:publish
发布配置文件
#config/csp-report.php return [ 'persist' => [ 'class' => LogCspPersister::class, 'properties' => [ 'loglevel' => Psr\Log\LogLevel::INFO ] ], 'limiter' => [ 'class' => CspCacheLimiter::class, 'properties' => [ 'key' => 'csp-rate-limiter', 'maxAttempts' => 1, 'decay' => 60 ] ], ];
默认情况下,插件会将违规存储在日志中,但还有一个 BugsnagPersister
会将违规发送到 bugsnag。
Craft 3
配置应用程序使用正确的限制器和持久器。
use Zae\ContentSecurityPolicyReporting\Contracts\CspLimiter; use Zae\ContentSecurityPolicyReporting\Contracts\CspPersistable; use Zae\ContentSecurityPolicyReporting\Limiters\CspLotteryLimiter; use Zae\ContentSecurityPolicyReporting\Persisters\BugsnagCspPersister; return [ 'bootstrap' => [ 'csp-reporting' ], 'components' => [ 'csp-reporting' => [ 'class' => \Zae\ContentSecurityPolicyReporting\Craft\Module::class, 'components' => [ CspPersistable::class => static function () { return new BugsnagCspPersister( \Bugsnag\Client::make(getenv('BUGSNAG_API_KEY')) ); }, CspLimiter::class => static function () { return new CspLotteryLimiter(5); } ] ], ] ]
在高流量网站上,违规可能会经常发生,并且可能都是相同的,因此限制器将确保只有一部分违规会被实际存储。
属性数组将允许您配置处理程序。
只要它们实现了正确的接口,您也可以提供自己的类。
提供的限制器
CspCacheLimiter
CspLotteryLimiter
提供的持久器
LogCspPersister
BugsnagCspPersister
测试
$ composer run test
贡献
欢迎通过在 github 上提交 pull requests 进行贡献。
鸣谢
许可证
MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件。