Content-Security-Policy ####################### .. note:: 跨域脚本攻击 XSS 是最常见、危害最大的网页安全漏洞。为了防止它们,要采取很多编程措施,非常麻烦。很多人提出,能不能根本上解决问题,浏览器自动禁止外部注入恶意脚本?这就是 "网页安全政策"(Content Security Policy,缩写 CSP)的来历。 简介:: CSP 的实质就是白名单制度,开发者明确告诉客户端,哪些外部资源可以加载和执行,等同于提供白名单。 它的实现和执行全部由浏览器完成,开发者只需提供配置。 作用:: CSP 大大增强了网页的安全性。 攻击者即使发现了漏洞,也没法注入脚本,除非还控制了一台列入了白名单的可信主机。 Syntax:: Content-Security-Policy: ; Directives ========== * 参考: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy#directives Fetch directives ---------------- Fetch directives control the locations from which certain resource types may be loaded. child-src:: Defines the valid sources for web workers and nested browsing contexts loaded using elements such as and