From 3927ddec3e79a16e3e0b3ced1f2d26a709cf2e91 Mon Sep 17 00:00:00 2001 From: Alexander Bakker Date: Sun, 9 Oct 2022 11:27:20 +0200 Subject: [PATCH] Make vault lock intent used in notifications more explicit Aegis can display a notification to the user as a reminder that the vault is unlocked. If the user taps the notification, the vault is locked. CodeQL reported that Aegis may be vulnerable to CWE-927, because of the use of an implicit intent wrapped by a PendingIntent in that notification. This does not appear to be exploitable in our case, because we use ``PendingIntent.getBroadcast`` and explicitly set the action of the wrapped intent. Aegis also does not read or act on any information from the received intent. This means that a malicious app cannot launch activities or send a broadcast with a different action, as is common with these type of weakness. The worst an app with notification access can do, is lock the vault. Either way, it's good to make the intent explicit, so this patch addresses that. Additionally, for API level 23 and up, we've made the wrapped intent immutable a while back. We'd like to thank John Rune, who ran a CodeQL scan on the Aegis codebase and privately disclosed this finding to us. --- app/src/main/AndroidManifest.xml | 7 ++++ .../aegis/AegisApplicationBase.java | 20 ----------- .../aegis/receivers/VaultLockReceiver.java | 34 +++++++++++++++++++ .../aegis/services/NotificationService.java | 25 ++++++++------ 4 files changed, 56 insertions(+), 30 deletions(-) create mode 100644 app/src/main/java/com/beemdevelopment/aegis/receivers/VaultLockReceiver.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c5bcd524..c3c5a1e9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -93,6 +93,13 @@ + + + + + + + = Build.VERSION_CODES.M) { flags |= PendingIntent.FLAG_IMMUTABLE; } - Intent intentAction = new Intent(CODE_LOCK_VAULT_ACTION); - PendingIntent lockDatabaseIntent = PendingIntent.getBroadcast(this, 1, intentAction, flags); - NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CODE_LOCK_STATUS_ID) + PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 1, intent, flags); + + NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID) .setSmallIcon(R.drawable.ic_aegis_notification) .setContentTitle(getString(R.string.app_name_full)) .setContentText(getString(R.string.vault_unlocked_state)) .setPriority(NotificationCompat.PRIORITY_DEFAULT) .setOngoing(true) - .setContentIntent(lockDatabaseIntent); + .setContentIntent(pendingIntent); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); - notificationManager.notify(VAULT_UNLOCKED_ID, builder.build()); + notificationManager.notify(NOTIFICATION_VAULT_UNLOCKED, builder.build()); } @Override public void onDestroy() { NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); - notificationManager.cancel(VAULT_UNLOCKED_ID); + notificationManager.cancel(NOTIFICATION_VAULT_UNLOCKED); super.onDestroy(); }