我在API的响应中收到了X-Frame-Options标头,但据我所知,为了防止点击劫持攻击,我需要在UI代码中添加它. UI代码(以
angularjs编写)部署在Tomcat(版本7.0.72)服务器中.我尝试在我的应用程序的web.xml中添加以下过滤器.
<filter> <filter-name>httpHeaderSecurity</filter-name> <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class> <async-supported>true</async-supported> <init-param> <param-name>antiClickJackingEnabled</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>antiClickJackingOption</param-name> <param-value>DENY</param-value> </init-param> </filter>
我找到了解决方案.需要通过Tomcat服务器上的web.xml添加X-Frame-Options响应头.我的web.xml中缺少过滤器映射,因此未添加标头.对于其他可能遇到此问题的人,我在这里发布了来自web.xml的行:
<filter> <filter-name>httpHeaderSecurity</filter-name> <filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class> <async-supported>true</async-supported> <init-param> <param-name>antiClickJackingEnabled</param-name> <param-value>true</param-value> </init-param> <init-param> <param-name>antiClickJackingOption</param-name> <param-value>DENY</param-value> </init-param> </filter> <filter-mapping> <filter-name>httpHeaderSecurity</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list>
有了这个,添加以下标题:
•X-Frame-Options
•X-Content-Type-Options
•X-XSS-Protection
如果没有为每个标头指定值,则将设置每个标头的默认值.您可以在Tomcat服务器文档中找到默认值.