bnomei / kirby3-security-headers
Kirby 插件,用于简化安全头部设置
Requires
- php: >=8.1.0
- getkirby/composer-installer: ^1.2
- paragonie/csp-builder: ^2.5
Requires (Dev)
- getkirby/cms: ^4.0
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^9.5
Suggests
- bnomei/kirby3-doctor: Add a panel button to check health and security of your Kirby installation
- dev-master
- 4.0.0
- 2.5.5
- 2.5.4
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.2
- 2.4.1
- 2.4.0
- 2.3.2
- 2.3.1
- 2.3.0
- 2.2.5
- 2.2.4
- 2.2.3
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.0
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0.0
- 1.1.3
- 1.1.2
- 1.1.1
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.6.1
- 0.6.0
- 0.5.7
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.5.0
- dev-dependabot/composer/getkirby/cms-3.6.6.2
- dev-dependabot/composer/guzzlehttp/guzzle-7.7.0
- dev-dependabot/composer/guzzlehttp/psr7-2.5.0
This package is auto-updated.
Last update: 2024-08-30 11:54:38 UTC
README
Kirby 插件,用于简化安全头部设置。
🔐 为什么你应该使用这个插件?因为安全很重要。保护你或你的客户的网站及其客户数据是重要的。
商业使用
支持开源!
这个插件是免费的,但如果你在商业项目中使用它,请考虑赞助我或捐款。
如果我的工作帮助你赚了一些钱,我认为我可能也应该得到一些回报,对吗?
行善。分享一点。谢谢。
—— Bruno
安装
- 将 master.zip 解压为文件夹
site/plugins/kirby3-security-headers
或 git submodule add https://github.com/bnomei/kirby3-security-headers.git site/plugins/kirby3-security-headers
或composer require bnomei/kirby3-security-headers
设置
自动
一个 route:before
钩子负责自动设置头部,除非以下条件之一适用
- Kirby 的 全局 调试模式设置为
true
- Kirby 判断这是一个 本地设置
- 插件设置
enabled
设置为false
头部
以下头部将默认应用。您可以在配置文件中覆盖它们。
/site/config/config.php
<?php return [ 'bnomei.securityheaders.headers' => [ "X-Powered-By" => "", // unset "X-Frame-Options" => "SAMEORIGIN", "X-XSS-Protection" => "1; mode=block", "X-Content-Type-Options" => "nosniff", "strict-transport-security" => "max-age=31536000; includeSubdomains", "Referrer-Policy" => "no-referrer-when-downgrade", "Permissions-Policy" => 'interest-cohort=()', // flock-off, // ... FEATURE POLICIES // other options... ];
加载器
加载器用于使用给定的一组数据初始化 CSPBuilder 对象。您可以跳过该步骤,传递一个文件进行加载,提供一个数组或使用默认的加载器文件。在添加额外的 font-src 为 google web fonts 等情况下,建议使用自定义文件。
/site/config/config.php
<?php return [ 'bnomei.securityheaders.loader' => function () { // https://github.com/paragonie/csp-builder#example // null if you do NOT want to use default and/or just the setter /* return null; */ // return path of file (json or yaml) // or an array of options for the cspbuilder /* return [...]; return kirby()->roots()->site() . '/your-csp.json'; return kirby()->roots()->site() . '/your-csp.yml'; */ // otherwise forward the default file from this plugin return __DIR__ . '/loader.json'; }, // other options... ];
设置器
设置器在加载器之后应用。使用它添加动态内容,如哈希和非ce。
/site/config/config.php
<?php return [ 'bnomei.securityheaders.setter' => function (\Bnomei\SecurityHeaders $instance) { // https://github.com/paragonie/csp-builder#build-a-content-security-policy-programmatically /** @var ParagonIE\CSPBuilder\CSPBuilder $csp */ /* $csp = $instance->csp(); $nonce = $instance->setNonce('my-inline-script'); $csp->nonce('script-src', $nonce); */ // in your template retrieve it again with /* $nonce = $page->nonce('my-inline-script'); => `THIS-IS-THE-NONCE` $attr = $page->nonceAttr('my-inline-script'); => `nonce="THIS-IS-THE-NONCE"` */ }, // other options... ];
提示:nonce 在
setter
中设置,稍后使用$page->nonce(...)
或$page->nonceAttr(...)
获取。
面板和前端 Nonce
此插件自动注册 Kirby 的 nonce 以供面板使用。为了方便起见,它还提供了一个单个的 前端 nonce,您可以用作 <link>
、<style>
和 <script>
元素的属性。您可以使用 site()->nonce()
获取 nonce,使用 site()->nonceAttr()
获取完整的属性。
<?php ?> <script nonce="<?= site()->nonce() ?>"> // ... </script> <style <?= site()->nonceAttr() ?>> </style>
提示:srcset 插件 也使用该 前端 nonce。
设置
依赖项
免责声明
本插件“原样”提供,不提供任何保证。自行承担使用风险,并在将其用于生产环境之前自行测试。如果您发现任何问题,请 创建新问题。
许可证
不建议在宣传种族主义、性别歧视、恐同、动物虐待、暴力或任何其他仇恨言论的项目中使用此插件。