Skip to content

Commit c15ce27

Browse files
committed
Add SqlConcatenatedQuery
1 parent 1af6d5f commit c15ce27

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

java/ql/lib/change-notes/2023-03-30-add-libraries-for-query-configurations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
category: minorAnalysis
33
---
44
* Added the `TaintedPermissionQuery.qll` library to provide the `TaintedPermissionFlow` taint-tracking module to reason about tainted permission vulnerabilities.
5+
* Added the `SqlConcatenatedQuery.qll` library to provide the `UncontrolledStringBuilderSourceFlow` taint-tracking module to reason about SQL injection vulnerabilities caused by concatenating untrusted strings.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/** Provides classes and modules to reason about SqlInjection vulnerabilities from string concatentation. */
2+
3+
import java
4+
import semmle.code.java.dataflow.TaintTracking
5+
private import semmle.code.java.security.SqlConcatenatedLib
6+
private import semmle.code.java.security.SqlInjectionQuery
7+
8+
private class UncontrolledStringBuilderSource extends DataFlow::ExprNode {
9+
UncontrolledStringBuilderSource() {
10+
exists(StringBuilderVar sbv |
11+
uncontrolledStringBuilderQuery(sbv, _) and
12+
this.getExpr() = sbv.getToStringCall()
13+
)
14+
}
15+
}
16+
17+
/**
18+
* A taint-tracking configuration for reasoning about uncontrolled string builders.
19+
*/
20+
module UncontrolledStringBuilderSourceFlowConfig implements DataFlow::ConfigSig {
21+
predicate isSource(DataFlow::Node src) { src instanceof UncontrolledStringBuilderSource }
22+
23+
predicate isSink(DataFlow::Node sink) { sink instanceof QueryInjectionSink }
24+
25+
predicate isBarrier(DataFlow::Node node) {
26+
node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType
27+
}
28+
}
29+
30+
/**
31+
* Taint-tracking flow for uncontrolled string builders that are used in a SQL query.
32+
*/
33+
module UncontrolledStringBuilderSourceFlow =
34+
TaintTracking::Global<UncontrolledStringBuilderSourceFlowConfig>;

java/ql/src/Security/CWE/CWE-089/SqlConcatenated.ql

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,7 @@
1515
import java
1616
import semmle.code.java.security.SqlConcatenatedLib
1717
import semmle.code.java.security.SqlInjectionQuery
18-
19-
class UncontrolledStringBuilderSource extends DataFlow::ExprNode {
20-
UncontrolledStringBuilderSource() {
21-
exists(StringBuilderVar sbv |
22-
uncontrolledStringBuilderQuery(sbv, _) and
23-
this.getExpr() = sbv.getToStringCall()
24-
)
25-
}
26-
}
27-
28-
module UncontrolledStringBuilderSourceFlowConfig implements DataFlow::ConfigSig {
29-
predicate isSource(DataFlow::Node src) { src instanceof UncontrolledStringBuilderSource }
30-
31-
predicate isSink(DataFlow::Node sink) { sink instanceof QueryInjectionSink }
32-
33-
predicate isBarrier(DataFlow::Node node) {
34-
node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType
35-
}
36-
}
37-
38-
module UncontrolledStringBuilderSourceFlow =
39-
TaintTracking::Global<UncontrolledStringBuilderSourceFlowConfig>;
18+
import semmle.code.java.security.SqlConcatenatedQuery
4019

4120
from QueryInjectionSink query, Expr uncontrolled
4221
where

0 commit comments

Comments
 (0)