1010import java .util .ArrayList ;
1111import ly .count .android .sdk .Countly ;
1212
13+ import static ly .count .android .sdk .messaging .CountlyPush .ALLOWED_CLASS_NAMES ;
14+ import static ly .count .android .sdk .messaging .CountlyPush .ALLOWED_PACKAGE_NAMES ;
1315import static ly .count .android .sdk .messaging .CountlyPush .EXTRA_ACTION_INDEX ;
1416import static ly .count .android .sdk .messaging .CountlyPush .EXTRA_INTENT ;
1517import static ly .count .android .sdk .messaging .CountlyPush .EXTRA_MESSAGE ;
16- import static ly .count .android .sdk .messaging .CountlyPush .ALLOWED_CLASS_NAMES ;
17- import static ly .count .android .sdk .messaging .CountlyPush .ALLOWED_PACKAGE_NAMES ;
1818import static ly .count .android .sdk .messaging .CountlyPush .useAdditionalIntentRedirectionChecks ;
1919
2020public class CountlyPushActivity extends Activity {
@@ -42,11 +42,35 @@ private void performPushAction(Intent activityIntent) {
4242 int flags = intent .getFlags ();
4343 if (((flags & Intent .FLAG_GRANT_READ_URI_PERMISSION ) != 0 ) || ((flags & Intent .FLAG_GRANT_WRITE_URI_PERMISSION ) != 0 )) {
4444 Countly .sharedInstance ().L .w ("[CountlyPush, CountlyPushActivity] Attempt to get URI permissions" );
45+ // Remove not trusted URI flags
46+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
47+ Countly .sharedInstance ().L .d ("[CountlyPush, CountlyPushActivity] Removed URI permissions" );
48+ intent .removeFlags (Intent .FLAG_GRANT_READ_URI_PERMISSION );
49+ intent .removeFlags (Intent .FLAG_GRANT_WRITE_URI_PERMISSION );
50+ } else {
51+ Countly .sharedInstance ().L .d ("[CountlyPush, CountlyPushActivity] Can not remove URI permissions. Aborting" );
52+ return ;
53+ }
54+ }
55+
56+ ComponentName componentName = getCallingActivity ();
57+ String packageNameCurrent = getPackageName ();
58+ if (componentName != null ) {
59+ String callingPackage = componentName .getPackageName ();
60+ if (!callingPackage .startsWith (packageNameCurrent ) || !packageNameCurrent .equals (callingPackage )) {
61+ Countly .sharedInstance ().L .w ("[CountlyPushActivity] performPushAction, Untrusted intent package" );
62+ return ;
63+ }
64+ }
65+
66+ ComponentName targetComponent = intent .resolveActivity (context .getPackageManager ());
67+ if (targetComponent == null || !targetComponent .getPackageName ().startsWith (packageNameCurrent ) || !targetComponent .getPackageName ().equals (packageNameCurrent )) {
68+ Countly .sharedInstance ().L .w ("[CountlyPushActivity] performPushAction, Untrusted target component" );
4569 return ;
4670 }
4771
4872 if (useAdditionalIntentRedirectionChecks ) {
49- ComponentName componentName = intent .getComponent ();
73+ componentName = intent .getComponent ();
5074 String intentPackageName = componentName .getPackageName ();
5175 String intentClassName = componentName .getClassName ();
5276 String contextPackageName = context .getPackageName ();
@@ -123,7 +147,7 @@ private void performPushAction(Intent activityIntent) {
123147
124148 try {
125149 //try/catch required due to Android 12
126- if (android . os . Build .VERSION .SDK_INT < Build .VERSION_CODES .S ) {
150+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .S ) {
127151 //this needs to be called before Android 12
128152 Intent closeNotificationsPanel = new Intent (Intent .ACTION_CLOSE_SYSTEM_DIALOGS );
129153 context .sendBroadcast (closeNotificationsPanel );
@@ -165,4 +189,4 @@ private void performPushAction(Intent activityIntent) {
165189 }
166190 }
167191 }
168- }
192+ }
0 commit comments