相关文章推荐
安静的人字拖  ·  Swagger中的对象列表·  3 周前    · 
安静的人字拖  ·  详解C# ...·  7 月前    · 
安静的人字拖  ·  push() / Reference / ...·  9 月前    · 
威武的香瓜  ·  [转]Entity Framework ...·  8 小时前    · 
Default Security HTTP Response Headers
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=31536000 ; includeSubDomains
X-Frame-Options: DENY
X-XSS-Protection: 0
Default Cache Control HTTP Response Headers
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0

为了安全起见,Spring Security 默认添加了这些 Header。然而,如果你的应用程序提供了自己的缓存控制 Header,Spring Security 就会退居二线。这允许应用程序确保静态资源(如CSS和JavaScript)可以被缓存。

内容嗅探的问题在于,这使得恶意用户可以使用多语言(即一个文件可以作为多种内容类型有效)来进行XSS攻击。例如,一些网站可能允许用户提交一个有效的postscript文件到网站上并查看它。恶意用户可能会创建 一个也是有效的JavaScript文件的postscript文档 ,并利用它进行XSS攻击。

默认情况下,Spring Security 通过向 HTTP 响应添加以下头来禁用内容嗅探。

nosniff HTTP Response Header
X-Content-Type-Options: nosniff

当你输入银行的网站时,你是输入 mybank.example.com 还是输入 https://mybank.example.com ?如果你省略了https协议,你就有可能受到中间人攻击。即使网站执行重定向到 https://mybank.example.com ,一个恶意的用户可以拦截最初的HTTP请求并操纵响应(例如,重定向到 https://mibank.example.com ,并窃取他们的证书)。

许多用户省略了https协议,这就是 HTTP严格传输安全(HSTS) 产生的原因。一旦 mybank.example.com 被添加为 HSTS host ,浏览器可以提前知道任何对 mybank.example.com 的请求都应该被解释为 https://mybank.example.com 。这大大减少了中间人攻击发生的可能性。

一个网站被标记为 HSTS HOST 的方法是将该 HOST 预装到浏览器中。另一种方法是在响应中添加 Strict-Transport-Security header。例如,Spring Security 的默认行为是添加以下 header,指示浏览器将该域作为HSTS HOST处理一年(在非闰年有31536000秒)。

Strict Transport Security HTTP Response Header
Strict-Transport-Security: max-age=31536000 ; includeSubDomains ; preload

可选的 includeSubDomains 指令指示浏览器,子域(如 secure.mybank.example.com )也应被视为HSTS域。

可选的 preload 指令指示浏览器,该域应作为 HSTS 域在浏览器中预加载。关于HSTS预加载的更多细节,请参见 hstspreload.org

HTTP公钥锁定(HTTP Public Key Pinning) (HPKP)向网络客户指定在某个网络服务器上使用哪个公钥,以防止使用伪造证书的中间人(MITM)攻击。如果使用得当,HPKP可以增加额外的保护层,防止证书被破坏。然而,由于HPKP的复杂性,许多专家不再建议使用它, Chrome浏览器甚至取消了对它的支持

关于为什么不再推荐HPKP的其他细节,请阅读 Is HTTP Public Key Pinning Dead? I’m giving up on HPKP .

有许多方法可以减轻点击劫持攻击。例如,为了保护传统的浏览器免受点击劫持攻击,你可以使用 frame breaking code 。虽然不完美,但对于传统的浏览器来说,frame breaking code 是你能做的最好的。

解决点击劫持的一个更现代的方法是使用 X-Frame-Options 头。默认情况下,Spring Security 通过使用以下 Header 来禁止在 iframe 内渲染页面。

X-Frame-Options: DENY

试图从 script-src 指令中声明的以外的其他来源加载脚本会被用户代理(user-agent)阻止。此外,如果安全策略中声明了 report-uri 指令,用户代理将向声明的URL报告违规行为。

例如,如果一个Web应用程序违反了声明的安全策略,下面的响应头指示用户代理将违规报告发送到策略的 report-uri 指令中指定的URL。

Content Security Policy with report-uri
Content-Security-Policy: script-src https://trustedscripts.example.com; report-uri /csp-report-endpoint/

违规报告 是标准的JSON结构,可以由web应用程序自身的API或由公开托管的CSP违规报告服务(如 report-uri.io/ )捕获。

Content-Security-Policy-Report-Only Header 为 web 应用程序作者和管理员提供了监控安全策略的能力,而不是强制执行这些策略。这个 Header 通常在为网站试验或开发安全策略时使用。当一个策略被认为是有效的,它可以通过使用 Content-Security-Policy Header 来代替执行。

考虑到下面的响应头,该策略声明脚本可以从两个可能的来源之一加载。

Content Security Policy Report Only
Content-Security-Policy-Report-Only: script-src 'self' https://trustedscripts.example.com; report-uri /csp-report-endpoint/

如果网站违反了这一政策,试图从 evil.example.com 加载一个脚本,用户代理会向 report-uri 指令指定的声明的URL发送一份违规报告,但仍让违规资源加载。

将内容安全策略应用于 web 应用程序往往是一项非同小可的工作。以下资源可以为你的网站制定有效的安全策略提供进一步的帮助。

内容安全策略简介

CSP指南 - Mozilla Developer Network

W3C候选建议

© VMware , Inc. or its affiliates. Terms of Use Privacy Trademark Guidelines Thank you Your California Privacy Rights Cookie Settings

Apache®, Apache Tomcat®, Apache Kafka®, Apache Cassandra™, and Apache Geode™ are trademarks or registered trademarks of the Apache Software Foundation in the United States and/or other countries. Java™, Java™ SE, Java™ EE, and OpenJDK™ are trademarks of Oracle and/or its affiliates. Kubernetes® is a registered trademark of the Linux Foundation in the United States and other countries. Linux® is the registered trademark of Linus Torvalds in the United States and other countries. Windows® and Microsoft® Azure are registered trademarks of Microsoft Corporation. “AWS” and “Amazon Web Services” are trademarks or registered trademarks of Amazon.com Inc. or its affiliates. All other trademarks and copyrights are property of their respective owners and are only mentioned for informative purposes. Other names may be trademarks of their respective owners.

 
推荐文章