Skip to content

Commit fe354b8

Browse files
authored
Sanitize intents in BrowserActivity (#1101)
1 parent 7105e5d commit fe354b8

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import com.duckduckgo.app.global.ApplicationClearDataState
4343
import com.duckduckgo.app.global.DuckDuckGoActivity
4444
import com.duckduckgo.app.global.events.db.UserEventsStore
4545
import com.duckduckgo.app.global.intentText
46+
import com.duckduckgo.app.global.sanitize
4647
import com.duckduckgo.app.global.view.*
4748
import com.duckduckgo.app.location.ui.LocationPermissionsActivity
4849
import com.duckduckgo.app.onboarding.ui.page.DefaultBrowserPage
@@ -133,6 +134,9 @@ class BrowserActivity : DuckDuckGoActivity(), CoroutineScope by MainScope() {
133134
override fun onNewIntent(intent: Intent?) {
134135
super.onNewIntent(intent)
135136
Timber.i("onNewIntent: $intent")
137+
138+
intent?.sanitize()
139+
136140
dataClearerForegroundAppRestartPixel.registerIntent(intent)
137141

138142
if (dataClearer.dataClearerState.value == ApplicationClearDataState.FINISHED) {

app/src/main/java/com/duckduckgo/app/global/IntentExtension.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,27 @@
1717
package com.duckduckgo.app.global
1818

1919
import android.content.Intent
20+
import android.os.BadParcelableException
21+
import android.os.Bundle
22+
import timber.log.Timber
2023

2124
val Intent.intentText: String?
2225
get() {
2326
return data?.toString() ?: getStringExtra(Intent.EXTRA_TEXT)
2427
}
28+
29+
fun Intent.sanitize() {
30+
31+
try {
32+
// The strings are empty to force unparcel() call in BaseBundle
33+
getStringExtra("")
34+
getBooleanExtra("", false)
35+
} catch (e: BadParcelableException) {
36+
Timber.e(e, "Failed to read Parcelable from intent")
37+
replaceExtras(Bundle())
38+
39+
} catch (e: RuntimeException) {
40+
Timber.e(e, "Failed to receive extras from intent")
41+
replaceExtras(Bundle())
42+
}
43+
}

0 commit comments

Comments
 (0)