Skip to content

Commit 1f4028f

Browse files
committed
Java: Add new SQL sinks for Hibernate versions 4 and 6
1 parent bdcf419 commit 1f4028f

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

java/ql/src/semmle/code/java/frameworks/Hibernate.qll

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,36 @@
44

55
import java
66

7+
/** The interface `org.hibernate.query.QueryProducer`. */
8+
class HibernateQueryProducer extends RefType {
9+
HibernateQueryProducer() { this.hasQualifiedName("org.hibernate.query", "QueryProducer") }
10+
}
11+
12+
/** The interface `org.hibernate.SharedSessionContract`. */
13+
class HibernateSharedSessionContract extends RefType {
14+
HibernateSharedSessionContract() {
15+
this.hasQualifiedName("org.hibernate", "SharedSessionContract")
16+
}
17+
}
18+
719
/** The interface `org.hibernate.Session`. */
820
class HibernateSession extends RefType {
921
HibernateSession() { this.hasQualifiedName("org.hibernate", "Session") }
1022
}
1123

1224
/**
13-
* Holds if `m` is a method on `HibernateSession`, or a subclass, taking an SQL
14-
* string as its first argument.
25+
* Holds if `m` is a method on `HibernateQueryProducer`, or `HibernateSharedSessionContract`
26+
* or `HibernateSession`, or a subclass, taking an SQL string as its first argument.
1527
*/
1628
predicate hibernateSqlMethod(Method m) {
17-
m.getDeclaringType().getASourceSupertype*() instanceof HibernateSession and
29+
exists(RefType t |
30+
t = m.getDeclaringType().getASourceSupertype*() and
31+
(
32+
t instanceof HibernateQueryProducer or
33+
t instanceof HibernateSharedSessionContract or
34+
t instanceof HibernateSession
35+
)
36+
) and
1837
m.getParameterType(0) instanceof TypeString and
19-
(
20-
m.hasName("createQuery") or
21-
m.hasName("createSQLQuery")
22-
)
38+
m.hasName(["createQuery", "createNativeQuery", "createSQLQuery"])
2339
}

0 commit comments

Comments
 (0)