安全配置Security Defenses
通过对Security Defenses的配置 ,可以对http头添加相应的安全配置 ,如csp, X-Frame-Options, X-Content-Type-Option等
1 X-Frame-Options
你的网站添加了X-Frame-Options之后,保存了自己的网站不被其它网站引用,比如其它网站想iframe你的网站,通过X-Frame-Options DENY之后,其它网站是不容许iframe你的网站的。
参考:https://www.rfc-editor.org/rfc/rfc7034
HTTP 响应头是用来给浏览器指示允许一个页面可否在 , 或者
如果在kc中配置了它,并且在其它网站想通过iframe嵌入KC的页面,那么,如果使用SAMEORIGIN
它会出现如下图提示;如果是同源网站,是可以通过iframe访问它的
2 Content Security Policy
你的网站需要引用外部资源,如你需要引用微信的js脚本,或者需要iframe微信的页面,这时,你需要配置自己网站的CSP,将微信添加到白名单即可,例如:frame-src 'self' https://www.recaptcha.net https://open.weixin.qq.com
参考:https://www.w3.org/TR/CSP/
"网页安全政策"(Content Security Policy,缩写 CSP)CSP 的实质就是白名单制度,开发者明确告诉客户端,哪些外部资源可以加载和执行,等同于提供白名单。它的实现和执行全部由浏览器完成,开发者只需提供配置。
# 不允许被嵌入,包括<frame>, <iframe>, <object>, <embed> 和 <applet>
Content-Security-Policy: frame-ancestors 'none'
# 只允许被同源的页面嵌入
Content-Security-Policy: frame-ancestors 'self'
# 只允许被白名单内的页面嵌入
Content-Security-Policy: frame-ancestors www.example.com
# 不允许被嵌入,包括<frame>, <iframe>, <embed> 和 <object>
X-Frame-Options: deny
# 只允许被同源的页面嵌入
X-Frame-Options: sameorigin
# (已废弃)只允许被白名单内的页面嵌入
X-Frame-Options: allow-from www.example.com
3 Content-Security-Policy-Report-Only
4 X-Content-Type-Options
参考: https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/X-Content-Type-Options
响应首部相当于一个提示标志,被服务器用来提示客户端一定要遵循在 Content-Type 首部中对 MIME 类型 的设定。
5 X-Robots-Tag
参考:https://http.dev/x-robots-tag
6 X-XSS-Protection
参考:https://owasp.org/www-project-secure-headers/#xxxsp