FindBugs无法检测到SQL注入

时间:2018-09-20 06:12:42

标签: java hibernate gradle findbugs

我遇到了一个情况,其中FindBugs没有在我的项目中检测到SQL注入。使用Gradle构建项目,并使用FindBugs插件。我正在使用休眠连接到数据库。以下是包含SQL注入的部分,

public List<String> fetchApplicationRequests(String applicationId,
        String fromDate, String toDate) throws ParseException {
    String sb = "SELECT * FROM table where applicationid = " + applicationId;
    Query query = getCurrentSession().createQuery(sb);
    query.setParameter("appId", applicationId);
    return (List<String>) query.list();
}

很明显,以上部分显示了SQL注入。当我使用Veracode运行同一项目时,它在我提到的部分显示了SQL注入。以下是build.gradle下的FindBugs插件部分。

apply plugin: "findbugs"

findbugs {
  toolVersion = '3.0.1'
  effort = "max"
  ignoreFailures = true
  findbugsTest.enabled = false
}
tasks.withType(FindBugs) {
  reports {
      xml.enabled = false
      html.enabled = true
 }
}

当我运行命令时:

> ./gradlew clean build

它显示了我的项目中在build/reports/findbugs/main.html下发现的错误的列表

下面是FindBugs检测到的错误列表,

  • 不良行为警告-6
  • 正确性警告-17
  • 国际化警告-31
  • 恶意代码漏洞警告-52
  • 性能警告-15
  • 道奇代码警告-46

我希望未检测到安全类别下的SQL注入

Bug description: FindBugs

如何解决此问题,或者有什么其他方法可以在项目中检测SQL注入?

1 个答案:

答案 0 :(得分:1)

升级到SpotBugs 3.1.7和findsecbugs-plugin-1.8.0.jar。然后你得到

This use of org/hibernate/Session.createQuery(Ljava/lang/String;)Lorg/hibernate/Query; can be vulnerable to SQL/HQL injection

该行

Query query = ...

(然后,当然要重写代码:))