Skip to content

Commit 6a3eadf

Browse files
committed
Refactor ImplicitPendingIntents
1 parent 8621a49 commit 6a3eadf

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

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

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import semmle.code.java.frameworks.android.PendingIntent
77
import semmle.code.java.security.ImplicitPendingIntents
88

99
/**
10+
* DEPRECATED: Use `ImplicitPendingIntentStartFlow` instead.
11+
*
1012
* A taint tracking configuration for implicit `PendingIntent`s
1113
* being wrapped in another implicit `Intent` that gets started.
1214
*/
13-
class ImplicitPendingIntentStartConf extends TaintTracking::Configuration {
15+
deprecated class ImplicitPendingIntentStartConf extends TaintTracking::Configuration {
1416
ImplicitPendingIntentStartConf() { this = "ImplicitPendingIntentStartConf" }
1517

1618
override predicate isSource(DataFlow::Node source, DataFlow::FlowState state) {
@@ -52,3 +54,50 @@ class ImplicitPendingIntentStartConf extends TaintTracking::Configuration {
5254
c instanceof DataFlow::ArrayContent
5355
}
5456
}
57+
58+
/**
59+
* A taint tracking configuration for implicit `PendingIntent`s
60+
* being wrapped in another implicit `Intent` that gets started.
61+
*/
62+
module ImplicitPendingIntentStartConfig implements DataFlow::StateConfigSig {
63+
class FlowState = DataFlow::FlowState;
64+
65+
predicate isSource(DataFlow::Node source, FlowState state) {
66+
source.(ImplicitPendingIntentSource).hasState(state)
67+
}
68+
69+
predicate isSink(DataFlow::Node sink, FlowState state) {
70+
sink.(ImplicitPendingIntentSink).hasState(state)
71+
}
72+
73+
predicate isBarrier(DataFlow::Node sanitizer) { sanitizer instanceof ExplicitIntentSanitizer }
74+
75+
predicate isBarrier(DataFlow::Node node, FlowState state) { none() }
76+
77+
predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
78+
any(ImplicitPendingIntentAdditionalTaintStep c).step(node1, node2)
79+
}
80+
81+
predicate isAdditionalFlowStep(
82+
DataFlow::Node node1, FlowState state1, DataFlow::Node node2, FlowState state2
83+
) {
84+
any(ImplicitPendingIntentAdditionalTaintStep c).step(node1, state1, node2, state2)
85+
}
86+
87+
predicate allowImplicitRead(DataFlow::Node node, DataFlow::ContentSet c) {
88+
isSink(node, _) and
89+
allowIntentExtrasImplicitRead(node, c)
90+
or
91+
isAdditionalFlowStep(node, _) and
92+
c.(DataFlow::FieldContent).getType() instanceof PendingIntent
93+
or
94+
// Allow implicit reads of Intent arrays for steps like getActivities
95+
// or sinks like startActivities
96+
(isSink(node, _) or isAdditionalFlowStep(node, _, _, _)) and
97+
node.getType().(Array).getElementType() instanceof TypeIntent and
98+
c instanceof DataFlow::ArrayContent
99+
}
100+
}
101+
102+
module ImplicitPendingIntentStartFlow =
103+
TaintTracking::GlobalWithState<ImplicitPendingIntentStartConfig>;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
import java
1616
import semmle.code.java.dataflow.DataFlow
1717
import semmle.code.java.security.ImplicitPendingIntentsQuery
18-
import DataFlow::PathGraph
18+
import ImplicitPendingIntentStartFlow::PathGraph
1919

20-
from DataFlow::PathNode source, DataFlow::PathNode sink
21-
where any(ImplicitPendingIntentStartConf conf).hasFlowPath(source, sink)
20+
from ImplicitPendingIntentStartFlow::PathNode source, ImplicitPendingIntentStartFlow::PathNode sink
21+
where ImplicitPendingIntentStartFlow::flowPath(source, sink)
2222
select sink.getNode(), source, sink,
2323
"$@ and sent to an unspecified third party through a PendingIntent.", source.getNode(),
2424
"An implicit Intent is created"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class ImplicitPendingIntentsTest extends InlineExpectationsTest {
99

1010
override predicate hasActualResult(Location location, string element, string tag, string value) {
1111
tag = "hasImplicitPendingIntent" and
12-
exists(DataFlow::Node sink | any(ImplicitPendingIntentStartConf c).hasFlowTo(sink) |
12+
exists(DataFlow::Node sink | ImplicitPendingIntentStartFlow::flowTo(sink) |
1313
sink.getLocation() = location and
1414
element = sink.toString() and
1515
value = ""

0 commit comments

Comments
 (0)