Skip to content

Commit 1527110

Browse files
authored
Merge pull request #404 from Countly/intentfix
feat: add intent package check
2 parents b061abe + 05824ca commit 1527110

File tree

5 files changed

+34
-10
lines changed

5 files changed

+34
-10
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
## XX.XX.XX
1+
## 24.7.5-RC1
22
* ! Minor breaking change ! All active views will now automatically stop when consent for "views" is revoked.
33

44
* The Android SDK now supports Android 15 (API level 35)
55
* The views will be stopped and restarted now while going to the background or foreground instead of resuming and pausing.
6-
6+
* Added further intent redirection vulnarability checks.
77
* Added new functions to ease the presenting the feedback widgets. Functions present the first matching feedback widget from the list.
88
* presentNPS(Context)
99
* presentNPS(Context, String)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ org.gradle.configureondemand=true
2222
android.useAndroidX=true
2323
android.enableJetifier=true
2424
# RELEASE FIELD SECTION
25-
VERSION_NAME=24.7.4
25+
VERSION_NAME=24.7.5-RC1
2626
GROUP=ly.count.android
2727
POM_URL=https://github.com/Countly/countly-sdk-android
2828
POM_SCM_URL=https://github.com/Countly/countly-sdk-android

sdk/src/androidTest/java/ly/count/android/sdk/TestUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class TestUtils {
4444
public final static String commonAppKey = "appkey";
4545
public final static String commonDeviceId = "1234";
4646
public final static String SDK_NAME = "java-native-android";
47-
public final static String SDK_VERSION = "24.7.4";
47+
public final static String SDK_VERSION = "24.7.5-RC1";
4848
public static final int MAX_THREAD_COUNT_PER_STACK_TRACE = 50;
4949

5050
public static class Activity2 extends Activity {

sdk/src/main/java/ly/count/android/sdk/Countly.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ of this software and associated documentation files (the "Software"), to deal
4747
*/
4848
public class Countly {
4949

50-
private final String DEFAULT_COUNTLY_SDK_VERSION_STRING = "24.7.4";
50+
private final String DEFAULT_COUNTLY_SDK_VERSION_STRING = "24.7.5-RC1";
5151

5252
/**
5353
* Used as request meta data on every request

sdk/src/main/java/ly/count/android/sdk/messaging/CountlyPushActivity.java

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
import java.util.ArrayList;
1111
import 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;
1315
import static ly.count.android.sdk.messaging.CountlyPush.EXTRA_ACTION_INDEX;
1416
import static ly.count.android.sdk.messaging.CountlyPush.EXTRA_INTENT;
1517
import 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;
1818
import static ly.count.android.sdk.messaging.CountlyPush.useAdditionalIntentRedirectionChecks;
1919

2020
public 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

Comments
 (0)