前言
之前讲过 CSRF。防 Cookie hacking 的。
也介绍过防 XSS 的 HtmlSanitizer。
今天再介绍多 2 个 CSP 和 X-Frame-Options。
CSP (Content Security Policy)
它是游览器的其中一种防 hack 机制。除 IE 以外,modern browser 老早就全部支持了,所以可以安心用。
它主要是防 html 里要加载的 resource。
比如 html 想加载 JavaScript, Image 等等,
首先游览器会去检查 CSP config,然后验证这些 resource 是否符合 config 要求,如果 ok 才加载,不 ok 就报错,不加载。
Define CSP
- X-Frame-Options Security Content Options Policyx-frame-options security content options content-security-policy content-security-policy security content policy content-security-policy security策略content options strict-transport-security x-content-type-options security content policy header x-frame-options x-frame-options options frame deny x-frame-options options frame x-frame-options options iframe nginx