|
1 | 1 | /** Definitions used by the queries for database query injection. */ |
2 | 2 |
|
3 | | -import semmle.code.java.Expr |
| 3 | +import java |
4 | 4 | import semmle.code.java.dataflow.FlowSources |
5 | | -import semmle.code.java.frameworks.android.SQLite |
6 | | -import semmle.code.java.frameworks.javaee.Persistence |
7 | | -import semmle.code.java.frameworks.SpringJdbc |
8 | | -import semmle.code.java.frameworks.MyBatis |
9 | | -import semmle.code.java.frameworks.Hibernate |
10 | | - |
11 | | -/** A sink for database query language injection vulnerabilities. */ |
12 | | -abstract class QueryInjectionSink extends DataFlow::ExprNode { } |
13 | | - |
14 | | -/** A sink for SQL injection vulnerabilities. */ |
15 | | -class SqlInjectionSink extends QueryInjectionSink { |
16 | | - SqlInjectionSink() { |
17 | | - this.getExpr() instanceof SqlExpr |
18 | | - or |
19 | | - exists(MethodAccess ma, Method m, int index | |
20 | | - ma.getMethod() = m and |
21 | | - ma.getArgument(index) = this.getExpr() |
22 | | - | |
23 | | - index = m.(SQLiteRunner).sqlIndex() |
24 | | - or |
25 | | - m instanceof BatchUpdateVarargsMethod |
26 | | - or |
27 | | - index = 0 and jdbcSqlMethod(m) |
28 | | - or |
29 | | - index = 0 and mybatisSqlMethod(m) |
30 | | - or |
31 | | - index = 0 and hibernateSqlMethod(m) |
32 | | - ) |
33 | | - } |
34 | | -} |
35 | | - |
36 | | -/** A sink for Java Persistence Query Language injection vulnerabilities. */ |
37 | | -class PersistenceQueryInjectionSink extends QueryInjectionSink { |
38 | | - PersistenceQueryInjectionSink() { |
39 | | - // the query (first) argument to a `createQuery` or `createNativeQuery` method on `EntityManager` |
40 | | - exists(MethodAccess call, TypeEntityManager em | call.getArgument(0) = this.getExpr() | |
41 | | - call.getMethod() = em.getACreateQueryMethod() or |
42 | | - call.getMethod() = em.getACreateNativeQueryMethod() |
43 | | - // note: `createNamedQuery` is safe, as it takes only the query name, |
44 | | - // and named queries can only be constructed using constants as the query text |
45 | | - ) |
46 | | - } |
47 | | -} |
| 5 | +import semmle.code.java.security.QueryInjection |
48 | 6 |
|
49 | 7 | private class QueryInjectionFlowConfig extends TaintTracking::Configuration { |
50 | 8 | QueryInjectionFlowConfig() { this = "SqlInjectionLib::QueryInjectionFlowConfig" } |
|
0 commit comments