Skip to content

Commit df5178d

Browse files
authored
Merge pull request #10330 from atorralba/atorralba/implicit-pendingintents-compat-sinks
Java: Add Implicit PendingIntents sinks for Compat classes
2 parents 714b37e + 8e0b489 commit df5178d

File tree

15 files changed

+363
-4
lines changed

15 files changed

+363
-4
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Added new sinks to the query `java/android/implict-pendingintents` to take into account the classes `androidx.core.app.NotificationManagerCompat` and `androidx.core.app.AlarmManagerCompat`.
5+

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ private class PendingIntentSentSinkModels extends SinkModelCsv {
102102
"android.app;NotificationManager;true;notify;(String,int,Notification);;Argument[2];pending-intent-sent;manual",
103103
"android.app;NotificationManager;true;notifyAsPackage;(String,String,int,Notification);;Argument[3];pending-intent-sent;manual",
104104
"android.app;NotificationManager;true;notifyAsUser;(String,int,Notification,UserHandle);;Argument[2];pending-intent-sent;manual",
105+
"androidx.core.app;NotificationManagerCompat;true;notify;(int,Notification);;Argument[1];pending-intent-sent;manual",
106+
"androidx.core.app;NotificationManagerCompat;true;notify;(String,int,Notification);;Argument[2];pending-intent-sent;manual",
105107
"android.app;PendingIntent;false;send;(Context,int,Intent,OnFinished,Handler,String,Bundle);;Argument[2];pending-intent-sent;manual",
106108
"android.app;PendingIntent;false;send;(Context,int,Intent,OnFinished,Handler,String);;Argument[2];pending-intent-sent;manual",
107109
"android.app;PendingIntent;false;send;(Context,int,Intent,OnFinished,Handler);;Argument[2];pending-intent-sent;manual",
@@ -115,6 +117,10 @@ private class PendingIntentSentSinkModels extends SinkModelCsv {
115117
"android.app;AlarmManager;true;setInexactRepeating;;;Argument[3];pending-intent-sent;manual",
116118
"android.app;AlarmManager;true;setRepeating;;;Argument[3];pending-intent-sent;manual",
117119
"android.app;AlarmManager;true;setWindow;(int,long,long,PendingIntent);;Argument[3];pending-intent-sent;manual",
120+
"androidx.core.app;AlarmManagerCompat;true;setAlarmClock;;;Argument[2..3];pending-intent-sent;manual",
121+
"androidx.core.app;AlarmManagerCompat;true;setAndAllowWhileIdle;;;Argument[3];pending-intent-sent;manual",
122+
"androidx.core.app;AlarmManagerCompat;true;setExact;;;Argument[3];pending-intent-sent;manual",
123+
"androidx.core.app;AlarmManagerCompat;true;setExactAndAllowWhileIdle;;;Argument[3];pending-intent-sent;manual",
118124
]
119125
}
120126
}

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import android.os.Bundle;
1515
import android.os.CancellationSignal;
1616
import android.os.RemoteException;
17+
import androidx.core.app.AlarmManagerCompat;
18+
import androidx.core.app.NotificationManagerCompat;
1719
import androidx.core.graphics.drawable.IconCompat;
1820
import androidx.slice.Slice;
1921
import androidx.slice.SliceProvider;
@@ -182,7 +184,7 @@ public static void testPendingIntentInANotification(Context ctx)
182184
Notification.Builder nBuilder =
183185
new Notification.Builder(ctx).addAction(aBuilder.build());
184186
Notification notification = nBuilder.build();
185-
NotificationManager nManager = new NotificationManager();
187+
NotificationManager nManager = null;
186188
nManager.notifyAsPackage("targetPackage", "tag", 0, notification); // $hasImplicitPendingIntent
187189
nManager.notify(0, notification); // $hasImplicitPendingIntent
188190
nManager.notifyAsUser("", 0, notification, null); // $hasImplicitPendingIntent
@@ -195,7 +197,7 @@ public static void testPendingIntentInANotification(Context ctx)
195197
Notification.Builder nBuilder =
196198
new Notification.Builder(ctx).addAction(aBuilder.build());
197199
Notification notification = nBuilder.build();
198-
NotificationManager nManager = new NotificationManager();
200+
NotificationManager nManager = null;
199201
nManager.notify(0, notification); // Safe
200202
}
201203
{
@@ -212,10 +214,21 @@ public static void testPendingIntentInANotification(Context ctx)
212214
Notification.Action action = new Notification.Action(0, "", pi2);
213215
Notification.Builder nBuilder = new Notification.Builder(ctx).addAction(action);
214216
Notification notification = nBuilder.build();
215-
NotificationManager noMan = new NotificationManager();
217+
NotificationManager noMan = null;
216218
noMan.notify(0, notification); // Safe
217219
}
218-
220+
// Compat sinks
221+
{
222+
Intent baseIntent = new Intent();
223+
PendingIntent pi = PendingIntent.getActivity(ctx, 0, baseIntent, 0);
224+
Notification.Action.Builder aBuilder = new Notification.Action.Builder(0, "", pi);
225+
Notification.Builder nBuilder =
226+
new Notification.Builder(ctx).addAction(aBuilder.build());
227+
Notification notification = nBuilder.build();
228+
NotificationManagerCompat nManager = null;
229+
nManager.notify(0, notification); // $hasImplicitPendingIntent
230+
nManager.notify("", 0, notification); // $hasImplicitPendingIntent
231+
}
219232
}
220233

221234
public static void testPendingIntentInAnAlarm(Context ctx) {
@@ -238,6 +251,16 @@ public static void testPendingIntentInAnAlarm(Context ctx) {
238251
PendingIntent.getActivity(ctx, 0, baseIntent, PendingIntent.FLAG_IMMUTABLE); // Sanitizer
239252
aManager.set(0, 0, pi); // Safe
240253
}
254+
// Compat sinks
255+
{
256+
Intent baseIntent = new Intent();
257+
PendingIntent pi = PendingIntent.getActivity(ctx, 0, baseIntent, 0);
258+
AlarmManagerCompat.setAlarmClock(aManager, 0, pi, null); // $hasImplicitPendingIntent
259+
AlarmManagerCompat.setAlarmClock(aManager, 0, null, pi); // $hasImplicitPendingIntent
260+
AlarmManagerCompat.setAndAllowWhileIdle(aManager, 0, 0, pi); // $hasImplicitPendingIntent
261+
AlarmManagerCompat.setExact(aManager, 0, 0, pi); // $hasImplicitPendingIntent
262+
AlarmManagerCompat.setExactAndAllowWhileIdle(aManager, 0, 0, pi); // $hasImplicitPendingIntent
263+
}
241264
}
242265

243266
static class TestActivity extends Activity {

java/ql/test/stubs/google-android-9.0.0/android/app/AppComponentFactory.java

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/google-android-9.0.0/android/app/AutomaticZenRule.java

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/google-android-9.0.0/android/service/notification/Condition.java

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/google-android-9.0.0/android/service/notification/StatusBarNotification.java

Lines changed: 37 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/google-android-9.0.0/android/service/notification/ZenPolicy.java

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/google-android-9.0.0/androidx/core/app/AlarmManagerCompat.java

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/ql/test/stubs/google-android-9.0.0/androidx/core/app/CoreComponentFactory.java

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)