Skip to content

Commit 2e6d9e6

Browse files
committed
Allow query-specific MaD barriers
This was implemented by Gemini 3 using the following prompt. In the commit with the hash 10c5a47 the go language library was updated. I want you to do the same for the java language library. Here are the steps to follow: - Find all .ql files in the java folder which are not in java/ql/src/experimental which contain the string "@kind path-problem". - Note the query id, as specified by the "@id" metadata at the top of the .ql file. It should have this format: "java/sql-injection". - These are path queries, so the second and third arguments in the select statement should have type "XFlow::PathNode"s for some module "XFlow" that is defined as something like "TaintTracking::Global<XFlowConfig>". Find the definition of the data flow config ("XFlowConfig" in my example code), which should be a module which implements `DataFlow::ConfigSig`. - If the module does not already define it, add a predicate like the following: `predicate isBarrier(DataFlow::Node node) { barrierNode(node, "Z") }` where "Z" should be the query id from earlier. - If the module already defines that predicate, add `or barrierNode(node, "Z")` to the end of the predicate body, where "Z" should be the query id.
1 parent 63329b4 commit 2e6d9e6

File tree

65 files changed

+262
-40
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+262
-40
lines changed

java/ql/lib/semmle/code/java/security/AndroidIntentRedirectionQuery.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,18 @@ import java
44
import semmle.code.java.dataflow.FlowSources
55
import semmle.code.java.dataflow.TaintTracking
66
import semmle.code.java.security.AndroidIntentRedirection
7+
import semmle.code.java.dataflow.ExternalFlow
78

89
/** A taint tracking configuration for tainted Intents being used to start Android components. */
910
module IntentRedirectionConfig implements DataFlow::ConfigSig {
1011
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }
1112

1213
predicate isSink(DataFlow::Node sink) { sink instanceof IntentRedirectionSink }
1314

14-
predicate isBarrier(DataFlow::Node sanitizer) { sanitizer instanceof IntentRedirectionSanitizer }
15+
predicate isBarrier(DataFlow::Node sanitizer) {
16+
sanitizer instanceof IntentRedirectionSanitizer or
17+
barrierNode(sanitizer, "java/android/intent-redirection")
18+
}
1519

1620
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
1721
any(IntentRedirectionAdditionalTaintStep c).step(node1, node2)

java/ql/lib/semmle/code/java/security/AndroidSensitiveCommunicationQuery.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import semmle.code.java.dataflow.TaintTracking
55
import semmle.code.java.frameworks.android.Intent
66
import semmle.code.java.security.SensitiveActions
77
private import semmle.code.java.dataflow.FlowSinks
8+
import semmle.code.java.dataflow.ExternalFlow
89

910
/**
1011
* Gets regular expression for matching names of Android variables that indicate the value being held contains sensitive information.
@@ -144,7 +145,10 @@ module SensitiveCommunicationConfig implements DataFlow::ConfigSig {
144145
/**
145146
* Holds if broadcast doesn't specify receiving package name of the 3rd party app
146147
*/
147-
predicate isBarrier(DataFlow::Node node) { node instanceof ExplicitIntentSanitizer }
148+
predicate isBarrier(DataFlow::Node node) {
149+
node instanceof ExplicitIntentSanitizer or
150+
barrierNode(node, "java/android/sensitive-communication")
151+
}
148152

149153
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
150154
isSink(node) and exists(c)

java/ql/lib/semmle/code/java/security/ArbitraryApkInstallationQuery.qll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java
44
import semmle.code.java.dataflow.DataFlow
55
import semmle.code.java.dataflow.TaintTracking
66
private import semmle.code.java.security.ArbitraryApkInstallation
7+
import semmle.code.java.dataflow.ExternalFlow
78

89
/**
910
* A dataflow configuration for flow from an external source of an APK to the
@@ -24,6 +25,10 @@ module ApkInstallationConfig implements DataFlow::ConfigSig {
2425
)
2526
}
2627

28+
predicate isBarrier(DataFlow::Node node) {
29+
barrierNode(node, "java/android/arbitrary-apk-installation")
30+
}
31+
2732
predicate observeDiffInformedIncrementalMode() { any() }
2833
}
2934

java/ql/lib/semmle/code/java/security/ArithmeticTaintedQuery.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
import java
44
private import semmle.code.java.dataflow.FlowSources
55
private import semmle.code.java.security.ArithmeticCommon
6+
import semmle.code.java.dataflow.ExternalFlow
67

78
/** A taint-tracking configuration to reason about overflow from unvalidated input. */
89
module ArithmeticOverflowConfig implements DataFlow::ConfigSig {
910
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }
1011

1112
predicate isSink(DataFlow::Node sink) { overflowSink(_, sink.asExpr()) }
1213

13-
predicate isBarrier(DataFlow::Node n) { overflowBarrier(n) }
14+
predicate isBarrier(DataFlow::Node n) {
15+
overflowBarrier(n) or
16+
barrierNode(n, "java/tainted-arithmetic")
17+
}
1418

1519
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
1620

@@ -34,6 +38,9 @@ deprecated module RemoteUserInputOverflowConfig = ArithmeticOverflowConfig;
3438
module ArithmeticUnderflowConfig implements DataFlow::ConfigSig {
3539
predicate isSource(DataFlow::Node source) { source instanceof ActiveThreatModelSource }
3640

41+
underflowBarrier(n) or
42+
barrierNode(n, "java/tainted-arithmetic")
43+
3744
predicate isSink(DataFlow::Node sink) { underflowSink(_, sink.asExpr()) }
3845

3946
predicate isBarrier(DataFlow::Node n) { underflowBarrier(n) }

java/ql/lib/semmle/code/java/security/ArithmeticUncontrolledQuery.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ private import semmle.code.java.dataflow.TaintTracking
55
private import semmle.code.java.security.RandomQuery
66
private import semmle.code.java.security.SecurityTests
77
private import semmle.code.java.security.ArithmeticCommon
8+
import semmle.code.java.dataflow.ExternalFlow
89

910
private class TaintSource extends DataFlow::ExprNode {
1011
TaintSource() {
@@ -18,7 +19,10 @@ module ArithmeticUncontrolledOverflowConfig implements DataFlow::ConfigSig {
1819

1920
predicate isSink(DataFlow::Node sink) { overflowSink(_, sink.asExpr()) }
2021

21-
predicate isBarrier(DataFlow::Node n) { overflowBarrier(n) }
22+
predicate isBarrier(DataFlow::Node n) {
23+
overflowBarrier(n) or
24+
barrierNode(n, "java/uncontrolled-arithmetic")
25+
}
2226

2327
predicate observeDiffInformedIncrementalMode() {
2428
any() // merged with ArithmeticUncontrolledUnderflow in ArithmeticUncontrolled.ql
@@ -39,6 +43,9 @@ module ArithmeticUncontrolledOverflowFlow =
3943
module ArithmeticUncontrolledUnderflowConfig implements DataFlow::ConfigSig {
4044
predicate isSource(DataFlow::Node source) { source instanceof TaintSource }
4145

46+
underflowBarrier(n) or
47+
barrierNode(n, "java/uncontrolled-arithmetic")
48+
4249
predicate isSink(DataFlow::Node sink) { underflowSink(_, sink.asExpr()) }
4350

4451
predicate isBarrier(DataFlow::Node n) { underflowBarrier(n) }

java/ql/lib/semmle/code/java/security/ArithmeticWithExtremeValuesQuery.qll

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java
44
private import semmle.code.java.dataflow.DataFlow
55
private import semmle.code.java.security.ArithmeticCommon
6+
import semmle.code.java.dataflow.ExternalFlow
67

78
/**
89
* A field representing an extreme value.
@@ -38,7 +39,10 @@ module MaxValueFlowConfig implements DataFlow::ConfigSig {
3839

3940
predicate isBarrierIn(DataFlow::Node n) { isSource(n) }
4041

41-
predicate isBarrier(DataFlow::Node n) { overflowBarrier(n) }
42+
predicate isBarrier(DataFlow::Node n) {
43+
overflowBarrier(n) or
44+
barrierNode(n, "java/extreme-value-arithmetic")
45+
}
4246
}
4347

4448
/** Dataflow from maximum values to an underflow. */
@@ -52,6 +56,9 @@ module MinValueFlowConfig implements DataFlow::ConfigSig {
5256

5357
predicate isSink(DataFlow::Node sink) { underflowSink(_, sink.asExpr()) }
5458

59+
underflowBarrier(n) or
60+
barrierNode(n, "java/extreme-value-arithmetic")
61+
5562
predicate isBarrierIn(DataFlow::Node n) { isSource(n) }
5663

5764
predicate isBarrier(DataFlow::Node n) { underflowBarrier(n) }

java/ql/lib/semmle/code/java/security/BrokenCryptoAlgorithmQuery.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import java
44
private import semmle.code.java.security.Encryption
55
private import semmle.code.java.dataflow.TaintTracking
66
private import semmle.code.java.security.Sanitizers
7+
import semmle.code.java.dataflow.ExternalFlow
78

89
private class ShortStringLiteral extends StringLiteral {
910
ShortStringLiteral() { this.getValue().length() < 100 }
@@ -31,7 +32,10 @@ module InsecureCryptoConfig implements DataFlow::ConfigSig {
3132

3233
predicate isSink(DataFlow::Node n) { exists(CryptoAlgoSpec c | n.asExpr() = c.getAlgoSpec()) }
3334

34-
predicate isBarrier(DataFlow::Node node) { node instanceof SimpleTypeSanitizer }
35+
predicate isBarrier(DataFlow::Node node) {
36+
node instanceof SimpleTypeSanitizer or
37+
barrierNode(node, "java/weak-cryptographic-algorithm")
38+
}
3539

3640
predicate observeDiffInformedIncrementalMode() { any() }
3741

java/ql/lib/semmle/code/java/security/CommandLineQuery.qll

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,10 @@ module InputToArgumentToExecFlowConfig implements DataFlow::ConfigSig {
5353

5454
predicate isSink(DataFlow::Node sink) { sink instanceof CommandInjectionSink }
5555

56-
predicate isBarrier(DataFlow::Node node) { node instanceof CommandInjectionSanitizer }
56+
predicate isBarrier(DataFlow::Node node) {
57+
node instanceof CommandInjectionSanitizer or
58+
barrierNode(node, "java/command-line-injection")
59+
}
5760

5861
predicate isAdditionalFlowStep(DataFlow::Node n1, DataFlow::Node n2) {
5962
any(CommandInjectionAdditionalTaintStep s).step(n1, n2)

java/ql/lib/semmle/code/java/security/ConditionalBypassQuery.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java
77
import semmle.code.java.dataflow.FlowSources
88
import semmle.code.java.security.SensitiveActions
99
import semmle.code.java.controlflow.Guards
10+
import semmle.code.java.dataflow.ExternalFlow
1011

1112
/**
1213
* Holds if `ma` is controlled by the condition expression `e`.
@@ -44,6 +45,8 @@ module ConditionalBypassFlowConfig implements DataFlow::ConfigSig {
4445

4546
predicate isSink(DataFlow::Node sink) { conditionControlsMethod(_, sink.asExpr()) }
4647

48+
predicate isBarrier(DataFlow::Node node) { barrierNode(node, "java/user-controlled-bypass") }
49+
4750
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
4851
endsWithStep(node1, node2)
4952
}

java/ql/lib/semmle/code/java/security/CsrfUnprotectedRequestTypeQuery.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ private module SqlExecuteConfig implements DataFlow::ConfigSig {
153153
m.hasName("execute")
154154
)
155155
}
156+
157+
predicate isBarrier(DataFlow::Node node) {
158+
barrierNode(node, "java/csrf-unprotected-request-type")
159+
}
156160
}
157161

158162
/**

0 commit comments

Comments
 (0)