Skip to content

Commit 4eba7e6

Browse files
Bernardo RufinoAndroid Build Coastguard Worker
authored andcommitted
Fix background bypass via notifications
This is a CP of ag/14736230 to qt-dev. Apps were able to bypass BAL and BG-FGS restrictions by retrieving their own notifications and firing their PI since those were allowlisted for those operations. Now we strip the token that granted them that ability from notifications returned via NM.getActiveNotifications(), which returns the notifications of the caller. Notifications returned via notification listener APIs still contain such token, as they should. Bug: 185388103 Bug: 169821287 Test: Manually tested Change-Id: I2ede0d639a560f6acacec3864a0a7d23af152ba5 Merged-In: I2ede0d639a560f6acacec3864a0a7d23af152ba5 (cherry picked from commit 5fbeff59df3ea1441c3843aa1834616876ef1985) (cherry picked from commit 14c1c7b4a732c517ba18f5dd0598adb9f3b72221)
1 parent 4ebfedd commit 4eba7e6

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

core/java/android/app/Notification.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3028,6 +3028,19 @@ public void setLatestEventInfo(Context context,
30283028
builder.build(); // callers expect this notification to be ready to use
30293029
}
30303030

3031+
/**
3032+
* Sets the token used for background operations for the pending intents associated with this
3033+
* notification.
3034+
*
3035+
* This token is automatically set during deserialization for you, you usually won't need to
3036+
* call this unless you want to change the existing token, if any.
3037+
*
3038+
* @hide
3039+
*/
3040+
public void setAllowlistToken(@Nullable IBinder token) {
3041+
mWhitelistToken = token;
3042+
}
3043+
30313044
/**
30323045
* @hide
30333046
*/

services/core/java/com/android/server/notification/NotificationManagerService.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3859,18 +3859,24 @@ public ParceledListSlice<StatusBarNotification> getAppActiveNotifications(String
38593859
}
38603860
}
38613861

3862+
/** Notifications returned here will have allowlistToken stripped from them. */
38623863
private StatusBarNotification sanitizeSbn(String pkg, int userId,
38633864
StatusBarNotification sbn) {
38643865
if (sbn.getUserId() == userId) {
38653866
if (sbn.getPackageName().equals(pkg) || sbn.getOpPkg().equals(pkg)) {
38663867
// We could pass back a cloneLight() but clients might get confused and
38673868
// try to send this thing back to notify() again, which would not work
38683869
// very well.
3870+
Notification notification = sbn.getNotification().clone();
3871+
// Remove background token before returning notification to untrusted app, this
3872+
// ensures the app isn't able to perform background operations that are
3873+
// associated with notification interactions.
3874+
notification.setAllowlistToken(null);
38693875
return new StatusBarNotification(
38703876
sbn.getPackageName(),
38713877
sbn.getOpPkg(),
38723878
sbn.getId(), sbn.getTag(), sbn.getUid(), sbn.getInitialPid(),
3873-
sbn.getNotification().clone(),
3879+
notification,
38743880
sbn.getUser(), sbn.getOverrideGroupKey(), sbn.getPostTime());
38753881
}
38763882
}

0 commit comments

Comments
 (0)