我正在使用Checkmarx来分析我的项目,唯一剩下的中等严重性项目是Missing_HSTS_Filter,目标名称是HSTSFilter。在我的web.xml中,我有:
<filter>
<filter-name>HSTSFilter</filter-name> <!-- checkmarx says problem is here -->
<filter-class>c.h.i.c.web.security.HSTSFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>HSTSFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>HSTSFilter类:
public class HSTSFilter implements Filter {
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
HttpServletResponse resp = (HttpServletResponse) res;
if (req.isSecure())
resp.setHeader("Strict-Transport-Security", "max-age=31622400; includeSubDomains");
chain.doFilter(req, resp);
}
}所以我尝试了其他方法,因为我使用的是Tomcat7,所以我尝试在web.xml中添加以下内容:
<filter> <!-- checkmarx now complains here -->
<filter-name>httpHeaderSecurity</filter-name>
<filter-class>org.apache.catalina.filters.HttpHeaderSecurityFilter</filter-class>
<async-supported>true</async-supported>
<init-param>
<param-name>hstsMaxAgeSeconds</param-name>
<param-value>31622400</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>httpHeaderSecurity</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>Checkmarx仍然抱怨,说这一次的目的地名称是StatementCollection。我不明白这是什么意思。
我错过了什么?
发布于 2019-10-04 17:11:46
奇怪的是。您确实使用了正确的配置。在这个Checkmarx规则中,我在一些扫描中发现了许多假阳性。无论如何,尝试将以下代码行添加到过滤器配置中的web.xml中:
<init-param>
<param-name>hstsIncludeSubDomains</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>hstsEnabled</param-name>
<param-value>true</param-value>
</init-param>https://stackoverflow.com/questions/58215452
复制相似问题