我的 Web 应用程序结构是
> App1.war
> -WEB-INF
> - web.xml
> - classes
> - config etc.
并且由于其他一些功能实现,我们添加了一个过滤器
<filter-mapping>
<filter-name>CustomerFilter</filter-name>
<url-pattern>/customer/pages/*</url-pattern>
</filter-mapping>
和过滤器类 CustomerFilter.java
public void doFilter(ServletRequest re, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
String requestURI = ((HttpServletRequest)re).getRequestURI();
if (requestURI.endsWith(".action")) {
chain.doFilter(request, response);
}
else {
request.getRequestDispatcher(
requestURI.replace(config.getServletContext().getContextPath() + "/customer/pages", ""))
.forward(request, response);
}
}
由于此更改,我可以通过 URL yourserver/App1/customer/pages/WEB-INF/web.xml 直接访问 web.xml,这是一个安全漏洞,因此我添加了一个安全约束来解决此泄漏。我的问题是我们还有其他方法可以有效地处理这个问题吗?或者目录遍历的其他解决方案是什么。前任:
<security-constraint>
<display-name>SecurityConstraintForDirA</display-name>
<web-resource-collection>
<web-resource-name>DirAResources</web-resource-name>
<url-pattern>customer/pages/WEB-INF/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>adm</role-name>
</auth-constraint>
</security-constraint>
请记住,我的应用程序是基于 struts 的旧 Web 应用程序。