Skip to content

Commit 91b3533

Browse files
committed
Add SqlTaintedLocalQuery
1 parent a0f7575 commit 91b3533

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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ category: minorAnalysis
88
* Added the `ExternallyControlledFormatStringLocalQuery.qll` library to provide the `ExternallyControlledFormatStringLocalFlow` taint-tracking module to reason about format string vulnerabilities caused by local data flow.
99
* Added the `InsecureCookieQuery.qll` library to provide the `SecureCookieFlow` taint-tracking module to reason about insecure cookie vulnerabilities.
1010
* Added the `ExecTaintedLocalQuery.qll` library to provide the `LocalUserInputToArgumentToExecFlow` taint-tracking module to reason about command injection vulnerabilities caused by local data flow.
11-
* Added the `StackTraceExposureQuery.qll` library to provide the `printsStackExternally`, `stringifiedStackFlowsExternally`, and `getMessageFlowsExternally` predicates to reason about stack trace exposure vulnerabilities.
11+
* Added the `StackTraceExposureQuery.qll` library to provide the `printsStackExternally`, `stringifiedStackFlowsExternally`, and `getMessageFlowsExternally` predicates to reason about stack trace exposure vulnerabilities.
12+
* Added the `SqlTaintedLocalQuery.qll` library to provide the `LocalUserInputToArgumentToSqlFlow` taint-tracking module to reason about SQL injection vulnerabilities caused by local data flow.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Provides a taint-tracking configuration for reasoning about local user input
3+
* that is used in a SQL query.
4+
*/
5+
6+
import semmle.code.java.Expr
7+
import semmle.code.java.dataflow.FlowSources
8+
import semmle.code.java.security.SqlInjectionQuery
9+
10+
/**
11+
* A taint-tracking configuration for reasoning about local user input that is
12+
* used in a SQL query.
13+
*/
14+
module LocalUserInputToQueryInjectionFlowConfig implements DataFlow::ConfigSig {
15+
predicate isSource(DataFlow::Node src) { src instanceof LocalUserInput }
16+
17+
predicate isSink(DataFlow::Node sink) { sink instanceof QueryInjectionSink }
18+
19+
predicate isBarrier(DataFlow::Node node) {
20+
node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType
21+
}
22+
23+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
24+
any(AdditionalQueryInjectionTaintStep s).step(node1, node2)
25+
}
26+
}
27+
28+
/**
29+
* Taint-tracking flow for local user input that is used in a SQL query.
30+
*/
31+
module LocalUserInputToQueryInjectionFlow =
32+
TaintTracking::Global<LocalUserInputToQueryInjectionFlowConfig>;

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

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,8 @@
1212
* external/cwe/cwe-564
1313
*/
1414

15-
import semmle.code.java.Expr
16-
import semmle.code.java.dataflow.FlowSources
17-
import semmle.code.java.security.SqlInjectionQuery
18-
19-
module LocalUserInputToQueryInjectionFlowConfig implements DataFlow::ConfigSig {
20-
predicate isSource(DataFlow::Node src) { src instanceof LocalUserInput }
21-
22-
predicate isSink(DataFlow::Node sink) { sink instanceof QueryInjectionSink }
23-
24-
predicate isBarrier(DataFlow::Node node) {
25-
node.getType() instanceof PrimitiveType or node.getType() instanceof BoxedType
26-
}
27-
28-
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
29-
any(AdditionalQueryInjectionTaintStep s).step(node1, node2)
30-
}
31-
}
32-
33-
module LocalUserInputToQueryInjectionFlow =
34-
TaintTracking::Global<LocalUserInputToQueryInjectionFlowConfig>;
35-
15+
import java
16+
import semmle.code.java.security.SqlTaintedLocalQuery
3617
import LocalUserInputToQueryInjectionFlow::PathGraph
3718

3819
from

0 commit comments

Comments
 (0)