Skip to content
This repository was archived by the owner on Mar 6, 2025. It is now read-only.

Commit 883fbcd

Browse files
committed
[BWA-10] Sanitize launch intents before processing
1 parent 17c9008 commit 883fbcd

File tree

2 files changed

+26
-5
lines changed

2 files changed

+26
-5
lines changed

app/src/main/kotlin/com/bitwarden/authenticator/MainActivity.kt

+13-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.bitwarden.authenticator
22

33
import android.content.Intent
44
import android.os.Bundle
5-
import android.util.Log
65
import android.view.WindowManager
76
import androidx.activity.compose.setContent
87
import androidx.activity.viewModels
@@ -11,6 +10,7 @@ import androidx.compose.runtime.getValue
1110
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
1211
import androidx.lifecycle.compose.collectAsStateWithLifecycle
1312
import androidx.lifecycle.lifecycleScope
13+
import com.bitwarden.authenticator.data.platform.util.isSuspicious
1414
import com.bitwarden.authenticator.ui.platform.feature.rootnav.RootNavScreen
1515
import com.bitwarden.authenticator.ui.platform.theme.AuthenticatorTheme
1616
import dagger.hilt.android.AndroidEntryPoint
@@ -23,6 +23,7 @@ class MainActivity : AppCompatActivity() {
2323
private val mainViewModel: MainViewModel by viewModels()
2424

2525
override fun onCreate(savedInstanceState: Bundle?) {
26+
sanitizeIntent()
2627
var shouldShowSplashScreen = true
2728
installSplashScreen().setKeepOnScreenCondition { shouldShowSplashScreen }
2829
super.onCreate(savedInstanceState)
@@ -53,18 +54,26 @@ class MainActivity : AppCompatActivity() {
5354

5455
override fun onNewIntent(intent: Intent) {
5556
super.onNewIntent(intent)
57+
sanitizeIntent()
5658
mainViewModel.trySendAction(
5759
MainAction.ReceiveNewIntent(intent = intent)
5860
)
5961
}
6062

63+
private fun sanitizeIntent() {
64+
if (intent.isSuspicious) {
65+
intent = Intent(
66+
/* packageContext = */ this,
67+
/* cls = */ MainActivity::class.java,
68+
)
69+
}
70+
}
71+
6172
private fun observeViewModelEvents() {
62-
Log.d("TAG", "observeViewModelEvents() called")
6373
mainViewModel
6474
.eventFlow
6575
.onEach { event ->
66-
Log.d("TAG", "observeViewModelEvents: onEach $event")
67-
when(event) {
76+
when (event) {
6877
is MainEvent.ScreenCaptureSettingChange -> {
6978
handleScreenCaptureSettingChange(event)
7079
}
@@ -74,7 +83,6 @@ class MainActivity : AppCompatActivity() {
7483
}
7584

7685
private fun handleScreenCaptureSettingChange(event: MainEvent.ScreenCaptureSettingChange) {
77-
Log.d("TAG", "handleScreenCaptureSettingChange() called with: event = $event")
7886
if (event.isAllowed) {
7987
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
8088
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.bitwarden.authenticator.data.platform.util
2+
3+
import android.content.Intent
4+
5+
/**
6+
* Returns true if this intent contains unexpected or suspicious data.
7+
*/
8+
val Intent.isSuspicious: Boolean
9+
get() {
10+
val containsSuspiciousExtras = extras?.isEmpty?.not() ?: false
11+
val containsSuspiciousData = data != null
12+
return containsSuspiciousData || containsSuspiciousExtras
13+
}

0 commit comments

Comments
 (0)