SonarQube Critical Violation 要求对 rest api web.xml 文件进行过滤

SonarQube Critical Violation asks for filter on rest api web.xml file

SonarQube 提示(规则“Web applications should use validation filters”)建议使用此兼容解决方案:

public class ValidatingHttpRequest extends HttpServletRequestWrapper {
  // ...
}

public class ValidationFilter implements javax.servlet.Filter {
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
    chain.doFilter(new ValidatingHttpRequest( (HttpServletRequest)request ), response);
  }
}

并在 web.xml 中:

<filter>
    <filter-name>ValidationFilter</filter-name>
    <filter-class>com.myco.servlet.ValidationFilter</filter-class>
</filter>

<filter-mapping>
    <filter-name>ValidationFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

但我不知道这里需要进行哪些验证。我的代码是 rest api(resteasy 实现),所有服务都在 "/rest/* 路径下。这是假阳性案例吗?

根据 OWASP,注入缺陷是最主要的应用程序安全风险之一 (link). The basic prevention idea includes automatic validation of all input values using the whitelist approach. In order to implement it in Java EE, OWASP suggests using a custom filter, you can find more details with some restrictive patterns here

tl;dr:Sonar 要求您过滤掉一些可能不安全的输入字符。

在我看来,这条规则过于笼统,并不适用于所有可能的应用程序 - 可以通过多种方式防止代码注入。