Skip to content

Commit 7f85dae

Browse files
committed
Add support for implicit field read flows
1 parent e58a858 commit 7f85dae

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,19 @@ class ImplicitPendingIntentStartConf extends TaintTracking::Configuration {
2323
sanitizer instanceof ExplicitIntentSanitizer
2424
}
2525

26+
override predicate isAdditionalTaintStep(DataFlow::Node node1, DataFlow::Node node2) {
27+
exists(Field f |
28+
f.getType() instanceof PendingIntent and
29+
node1.(DataFlow::PostUpdateNode).getPreUpdateNode() =
30+
DataFlow::getFieldQualifier(f.getAnAccess().(FieldWrite)) and
31+
node2.asExpr().(FieldRead).getField() = f
32+
)
33+
}
34+
2635
override predicate allowImplicitRead(DataFlow::Node node, DataFlow::Content c) {
27-
super.allowImplicitRead(node, c)
28-
or
29-
this.isSink(node)
36+
super.allowImplicitRead(node, c) or
37+
this.isSink(node) or
38+
this.isAdditionalTaintStep(node, _)
3039
}
3140
}
3241

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public static void test(Context ctx) throws PendingIntent.CanceledException {
9090

9191
static class TestSliceProvider extends SliceProvider {
9292

93+
private PendingIntent mPendingIntent;
94+
9395
@Override
9496
public Slice onBindSlice(Uri sliceUri) {
9597
if (sliceUri.getAuthority().equals("1")) {
@@ -110,7 +112,7 @@ public Slice onBindSlice(Uri sliceUri) {
110112
.setPrimaryAction(activityAction));
111113
return listBuilder.build(); // Safe
112114

113-
} else {
115+
} else if (sliceUri.getAuthority().equals("3")) {
114116
Intent baseIntent = new Intent();
115117
PendingIntent pi = PendingIntent.getActivity(getContext(), 0, baseIntent,
116118
PendingIntent.FLAG_IMMUTABLE); // Sanitizer
@@ -119,6 +121,14 @@ public Slice onBindSlice(Uri sliceUri) {
119121
listBuilder.addRow(new ListBuilder.RowBuilder().setTitle("Title")
120122
.setPrimaryAction(activityAction));
121123
return listBuilder.build(); // Safe
124+
125+
} else {
126+
// Testing implicit field read flows:
127+
// mPendingIntent is set in onCreateSliceProvider
128+
SliceAction action = SliceAction.createDeeplink(mPendingIntent, null, 0, "");
129+
ListBuilder listBuilder = new ListBuilder(getContext(), sliceUri, 0);
130+
listBuilder.addRow(new ListBuilder.RowBuilder(sliceUri).setPrimaryAction(action));
131+
return listBuilder.build(); // $hasTaintFlow
122132
}
123133
}
124134

@@ -136,12 +146,17 @@ public PendingIntent onCreatePermissionRequest(Uri sliceUri, String callingPacka
136146
}
137147
}
138148

139-
// Implementations needed for compilation
140149
@Override
141150
public boolean onCreateSliceProvider() {
151+
// Testing implicit field read flows:
152+
// mPendingIntent is used in onBindSlice
153+
Intent baseIntent = new Intent();
154+
mPendingIntent = PendingIntent.getActivity(getContext(), 0, baseIntent, 0);
142155
return true;
143156
}
144157

158+
// Implementations needed for compilation
159+
145160
@Override
146161
public AssetFileDescriptor openTypedAssetFile(Uri uri, String mimeTypeFilter, Bundle opts,
147162
CancellationSignal signal) throws RemoteException, FileNotFoundException {

0 commit comments

Comments
 (0)