Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java FindBugs未检测到SQL注入_Java_Hibernate_Gradle_Findbugs - Fatal编程技术网

Java FindBugs未检测到SQL注入

Java FindBugs未检测到SQL注入,java,hibernate,gradle,findbugs,Java,Hibernate,Gradle,Findbugs,我遇到了一个案例,FindBugs在我的项目中没有检测到SQL注入。该项目是使用Gradle和FindBugs插件构建的。我正在使用hibernate连接到数据库。下面是包含SQL注入的部分 public List<String> fetchApplicationRequests(String applicationId, String fromDate, String toDate) throws ParseException { String sb = "

我遇到了一个案例,FindBugs在我的项目中没有检测到SQL注入。该项目是使用Gradle和FindBugs插件构建的。我正在使用hibernate连接到数据库。下面是包含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();
}
当我运行命令时:

./gradlew干净构建
它在
build/reports/findbugs/main.html

以下是FindBugs检测到的错误列表

  • 不良行为警告-6
  • 正确性警告-17
  • 国际化警告-31
  • 恶意代码漏洞警告-52
  • 性能警告-15
  • 危险代码警告-46
我希望SQL注入属于未检测到的安全类别


如何解决这个问题,或者是否有其他方法可以检测项目中的SQL注入?

升级到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 = ...

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

我认为这里没有SQL注入的机会。如果字符串参数中传递了奇怪的内容,格式化程序将抛出异常,整个方法将失败。如果传递了有效的日期文字,则其结果不可能包含任何可利用的代码。您希望在SQL注入中得到什么输入?注意,您正在通过<代码> DateFormat < /COD>运行输入(至少我假设这是<代码>格式化程序< /代码>),除非您也将该模式作为输入,您应该在安全方面。@ PiT.T让我们考虑输入的日期字段是正确的格式。格式化程序的格式基于“yyyy-MM-dd HH:MM:ss”。@a_-horse_,没有名称,但Veracode显示为SQL注入漏洞,这是错误的。然后Veracode过于谨慎,没有考虑到将参数传递给返回定义良好结果的函数这一事实。在从字符串到日期再到字符串的转换过程中,输入参数中任何可利用的代码究竟应该如何生存?
Query query = ...