Skip to content

Commit 4b814ec

Browse files
committed
Java: Refactor SensitiveCommunication.ql.
1 parent ca8e013 commit 4b814ec

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,11 @@ private predicate isStartActivityOrServiceSink(DataFlow::Node arg) {
122122
}
123123

124124
/**
125+
* DEPRECATED: Use `SensitiveCommunicationFlow` instead.
126+
*
125127
* Taint configuration tracking flow from variables containing sensitive information to broadcast Intents.
126128
*/
127-
class SensitiveCommunicationConfig extends TaintTracking::Configuration {
129+
deprecated class SensitiveCommunicationConfig extends TaintTracking::Configuration {
128130
SensitiveCommunicationConfig() { this = "Sensitive Communication Configuration" }
129131

130132
override predicate isSource(DataFlow::Node source) {
@@ -148,3 +150,27 @@ class SensitiveCommunicationConfig extends TaintTracking::Configuration {
148150
this.isSink(node)
149151
}
150152
}
153+
154+
private module SensitiveCommunicationConfig implements DataFlow::ConfigSig {
155+
predicate isSource(DataFlow::Node source) { source.asExpr() instanceof SensitiveInfoExpr }
156+
157+
predicate isSink(DataFlow::Node sink) {
158+
isSensitiveBroadcastSink(sink)
159+
or
160+
isStartActivityOrServiceSink(sink)
161+
}
162+
163+
/**
164+
* Holds if broadcast doesn't specify receiving package name of the 3rd party app
165+
*/
166+
predicate isBarrier(DataFlow::Node node) { node instanceof ExplicitIntentSanitizer }
167+
168+
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
169+
isSink(node) and exists(c)
170+
}
171+
}
172+
173+
/**
174+
* Tracks taint flow from variables containing sensitive information to broadcast Intents.
175+
*/
176+
module SensitiveCommunicationFlow = TaintTracking::Make<SensitiveCommunicationConfig>;

java/ql/src/Security/CWE/CWE-927/SensitiveCommunication.ql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
import java
1515
import semmle.code.java.security.AndroidSensitiveCommunicationQuery
16-
import DataFlow::PathGraph
16+
import SensitiveCommunicationFlow::PathGraph
1717

18-
from SensitiveCommunicationConfig cfg, DataFlow::PathNode source, DataFlow::PathNode sink
19-
where cfg.hasFlowPath(source, sink)
18+
from SensitiveCommunicationFlow::PathNode source, SensitiveCommunicationFlow::PathNode sink
19+
where SensitiveCommunicationFlow::hasFlowPath(source, sink)
2020
select sink.getNode(), source, sink, "This call may leak $@.", source.getNode(),
2121
"sensitive information"

java/ql/test/query-tests/security/CWE-927/SensitiveCommunication.ql

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ import semmle.code.java.security.AndroidSensitiveCommunicationQuery
33
import TestUtilities.InlineExpectationsTest
44
import TestUtilities.InlineFlowTest
55

6-
class EnableLegacy extends EnableLegacyConfiguration {
7-
EnableLegacy() { exists(this) }
8-
}
9-
106
class HasFlowTest extends InlineFlowTest {
11-
override DataFlow::Configuration getTaintFlowConfig() {
12-
result = any(SensitiveCommunicationConfig c)
13-
}
7+
override predicate hasValueFlow(DataFlow::Node src, DataFlow::Node sink) { none() }
148

15-
override DataFlow::Configuration getValueFlowConfig() { none() }
9+
override predicate hasTaintFlow(DataFlow::Node src, DataFlow::Node sink) {
10+
SensitiveCommunicationFlow::hasFlow(src, sink)
11+
}
1612
}

0 commit comments

Comments
 (0)