basecom/magento2-csp-split-header
Composer 安装命令:
composer require basecom/magento2-csp-split-header
包简介
Magento 2 module to split oversized CSP headers into multiple headers.
README 文档
README
Important
As of Magento 2.4.7 it is no longer possible to deactivate the Magento CSP module.
With a growing Content Security Policies (CSP) whitelist, the problem can arise that the
headers Content-Security-Policy-Report-Only and/or Content-Security-Policy become so large that they exceed the
maximum permitted size of a header field, causing the web server to not process the response any further.
The CSP mechanism allows multiple policies to be specified for a resource, including via the Content-Security-Policy
header, the Content-Security-Policy-Report-Only header and a meta
element [MDN].
Therefore, the headers can be specified more than once.
This is where the module comes into play. It implements an after method plugin for the
method Magento\Csp\Model\Policy\Renderer\SimplePolicyHeaderRenderer::render, which replaces the existing CSP headers
via the method \Magento\Framework\App\Response\HttpInterface::setHeader. The header is read, split so that the syntax
remains valid, and replaced by the new headers. The result is a separate header for each directive, each of which should
no longer exceed the maximum permitted length of the web server.
Tip
If the headers are too large even after splitting, try to identify unnecessary Magento modules and remove them.
Installation
-
Install it into your Magento 2 project with composer:
composer require basecom/magento2-csp-split-header -
Enable module
bin/magento setup:upgrade
Configuration
| Config | Default Value | Description |
|---|---|---|
basecom_csp_split_header/settings/header_splitting_enable |
0 (disabled) | enables (1) / disables (0) the splitting of the CSP header |
basecom_csp_split_header/settings/max_header_size |
8000 | maximum allowed header field size |
These values can be updated in the system configuration under Basecom -> Content Security Policy -> Enable.
Example
-
CSP splitting disabled
Content-Security-Policy: default-src 'self' https://example.com; connect-src 'none'; script-src https://example.com/; -
CSP splitting enabled
Content-Security-Policy: default-src 'self' https://example.com; Content-Security-Policy: connect-src 'none'; Content-Security-Policy: script-src https://example.com/;
Known Issues
CSP header is not split correctly (#5)
Lower the maximum allowed header field size threshold in the config basecom_csp_split_header/settings/max_header_size.
Varnish 503 error (#7)
Increase the Varnish header sizehttp_resp_hdr_len. The default value is 8kb.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email magento@basecom.de instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
Copyright
© 2024 basecom GmbH & Co. KG
basecom/magento2-csp-split-header 适用场景与选型建议
basecom/magento2-csp-split-header 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 83.07k 次下载、GitHub Stars 达 52, 最近一次更新时间为 2024 年 08 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 basecom/magento2-csp-split-header 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 basecom/magento2-csp-split-header 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 83.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 52
- 点击次数: 35
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-06