assayer-pro/yii2-cspreport

内容安全策略报告的Yii2模块

安装次数: 4,301

依赖者: 0

建议者: 0

安全性: 0

星标: 2

关注者: 2

分支: 0

开放问题: 0

类型:yii2-extension

1.0.1 2016-02-20 15:43 UTC

This package is auto-updated.

Last update: 2024-09-14 05:11:47 UTC


README

内容安全策略报告的Yii2模块内容安全策略报告

安装

安装此扩展的首选方式是通过composer

  • 运行以下命令之一:
php composer.phar require --prefer-dist "assayer-pro/yii2-cspreport" "*"

或添加以下内容到您的应用程序的composer.json文件中的require部分:

"assayer-pro/yii2-cspreport" : "*"

使用方法

  • 在应用程序配置文件的模块部分添加一个新模块,例如:
    'modules' => [
        'csp-report' => [
            'class' => 'assayerpro\cspreport\Module',
            'message' => [
                'from' => 'admin@example.com',
                'to' => 'developer@example.com',
                'subject' => 'Content Security Policy Report',
            ],
        ],
    ],
  • 在应用程序配置文件的urlManager部分添加一个新规则,例如:
    'components' => [
    ...
        'urlManager' => [
            'rules' => [
                'csp-report' => 'csp-report/report/index',
            ],
        ],
    ...
    ],
  • 添加应用/csp-report解析器
    'components' => [
    ...
        'request' => [
            'parsers' => [
                'application/csp-report' => 'yii\web\JsonParser',
            ],
        ],
    ...
    ],
  • Apache内容安全策略头部

将以下内容添加到您的虚拟主机中的httpd.conf文件或到<.htaccess>文件中:

Header set Content-Security-Policy-Report-Only "default-src https:; script-src https: 'unsafe-eval' 'unsafe-inline'; style-src https: 'unsafe-inline'; img-src https: data:; font-src https: data:; report-uri /csp-report;"
  • Nginx内容安全策略头部

在您的服务器{}块中添加:

   add_header Content-Security-Policy-Report-Only "default-src https:; script-src https: 'unsafe-eval' 'unsafe-inline'; style-src https: 'unsafe-inline'; img-src https: data:; font-src https: data:; report-uri /csp-report";

您也可以始终附加到末尾,以确保nginx无论响应代码如何都发送头部。