commit | 55ba66d7c0d61b21f46b7a6246cd4d8403533033 | [log] [tgz] |
---|---|---|
author | zhibinliu <zhibinliu@google.com> | Fri Dec 20 08:14:09 2024 +0000 |
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | Fri Mar 21 22:44:29 2025 -0700 |
tree | c5af5c0ff74322fdef82960d7941dc8d613fff41 | |
parent | a0fddac57b65e599d1f26b395d2de36e3029df8f [diff] |
Check package name format before using it for SPA nav Bug: b/372895305 Test: unit test Flag: EXEMPT bug fix (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:b2ee5ccf5b79d50cf53a86716042f0e2d7ff42ad) Merged-In: Ife615c78c48a2d6f5b938c880c9c2128c5551644 Change-Id: Ife615c78c48a2d6f5b938c880c9c2128c5551644
diff --git a/src/com/android/settings/spa/SpaAppBridgeActivity.kt b/src/com/android/settings/spa/SpaAppBridgeActivity.kt index a68d220..67a5be9 100644 --- a/src/com/android/settings/spa/SpaAppBridgeActivity.kt +++ b/src/com/android/settings/spa/SpaAppBridgeActivity.kt
@@ -38,7 +38,7 @@ companion object { fun getDestinationForApp(destinationPrefix: String, intent: Intent): String? { - val packageName = intent.data?.schemeSpecificPart ?: return null + val packageName = intent.data?.schemeSpecificPart?.takeIf { Regex("^([a-zA-Z]\\w*\\.)*[a-zA-Z]\\w*$").matches(it) } ?: return null return "$destinationPrefix/$packageName/${UserHandle.myUserId()}" } }
diff --git a/tests/spa_unit/src/com/android/settings/spa/SpaAppBridgeActivityTest.kt b/tests/spa_unit/src/com/android/settings/spa/SpaAppBridgeActivityTest.kt index be2b5e0..134cdb4 100644 --- a/tests/spa_unit/src/com/android/settings/spa/SpaAppBridgeActivityTest.kt +++ b/tests/spa_unit/src/com/android/settings/spa/SpaAppBridgeActivityTest.kt
@@ -37,6 +37,16 @@ assertThat(destination).isEqualTo("$DESTINATION/$PACKAGE_NAME/${UserHandle.myUserId()}") } + @Test + fun getDestinationForApp_hasMalformedPackageName() { + val intent = Intent().apply { + data = Uri.parse("package:package.name/10#") + } + + val destination = getDestinationForApp(DESTINATION, intent) + + assertThat(destination).isNull() + } @Test fun getDestinationForApp_noPackageName() {