给网站增加浏览器安全策略

浏览器前端安全策略,之前开启PKP导致网站无法访问(配置错误)。

由于在CDN上面配置会把;给截断导致后面的数据不生效而导致失败或者配置不全。特意转到Nginx上面配置,然后又因为冲突把HSTS给消掉了,导致SSL评级从A+掉到A,不得不给每个server单独添加。

Content-Security-Policy:

add_header Content-Security-Policy "default-src 'self' https:; img-src * https: data:; object-src 'self' https:; script-src 'self' 'unsafe-inline' 'unsafe-eval' https:; style-src 'self' 'unsafe-inline' https:; font-src 'self' https: data:; upgrade-insecure-requests; block-all-mixed-content; report-uri /csp_report";

开始有unsafe-eval的,在前台没有看到警告就删除了,然后在后台首页就有这个相关的警告了。某个Tab页无法显示加上后就可以了,应该是插件导致的。虽然好像也可以不要这个吧。

X-Frame-Options:

add_header X-Frame-Options SAMEORIGIN;

X-Content-Type-Options:

add_header X-Content-Type-Options nosniff;

X-XSS-Protection:

add_header X-XSS-Protection "1;mode=block;report-uri=/xss_report";

Public-Key-Pins:

add_header Public-Key-Pins "pin-sha256='mD2/V21BdzEDxYD8/fE8L/yWUy/SdzYhFYrB1MdD794='; pin-sha256='AQ9FoQyLCOltL6v6MrkyQk2CU2UcZi+YkVoK1LEzSGQ='; max-age=2592000; report-uri='/hpkp-report'";

之前是在CDN上面配置的自定义Header头因为含有;导致被截断而导致出现《Public Key Pinning:部署失败,有待下次继续测试
》的问题。

ChiuYut

2021年9月20日

发布者

ChiuYut

咦?我是谁?这是什么地方? Ya ha!我是ChiuYut!这里是我的小破站!