Skip to content

Commit a2e0bf0

Browse files
committed
Bug 2011536 - sanitize intent before interacting with it. r=jonalmeida
We are seeing `ClassCastException`s in the crash report - this is likely to be happening because some external intent has serialized some class that our app doesn't know about. Calling this `sanitize()` function strips out unknown classes from the bundle. `Intent.putExtra()` will internally call unparcel(), which assumes the bundle is serializable, so we need to call sanitize before doing this. [Running a try here](https://treeherder.mozilla.org/jobs?repo=try&revision=9a328763a8bcbf33ecc7e9116aceaa5854f85157) Pull request: #50
1 parent b8350a4 commit a2e0bf0

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

mobile/android/fenix/app/src/main/java/org/mozilla/fenix/IntentReceiverActivity.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ class IntentReceiverActivity : Activity() {
4343
// DO NOT MOVE ANYTHING ABOVE THIS getProfilerTime CALL.
4444
val startTimeProfiler = components.core.engine.profiler?.getProfilerTime()
4545

46+
// The intent property is nullable, but the rest of the code below
47+
// assumes it is not. If it's null, then we make a new one and open
48+
// the HomeActivity.
49+
val intent = intent?.let { Intent(it) } ?: Intent()
50+
intent.sanitize().stripUnwantedFlags()
51+
4652
// DO NOT MOVE the app link intent launch type setting below the super.onCreate call
4753
// as it impacts the activity lifecycle observer and causes false launch type detection.
4854
// e.g. COLD launch is interpreted as WARM due to [Activity.onActivityCreated] being called
@@ -57,11 +63,6 @@ class IntentReceiverActivity : Activity() {
5763
super.onCreate(savedInstanceState)
5864
}
5965

60-
// The intent property is nullable, but the rest of the code below
61-
// assumes it is not. If it's null, then we make a new one and open
62-
// the HomeActivity.
63-
val intent = intent?.let { Intent(it) } ?: Intent()
64-
intent.sanitize().stripUnwantedFlags()
6566
processIntent(intent)
6667

6768
components.core.engine.profiler?.addMarker(
@@ -158,7 +159,7 @@ class IntentReceiverActivity : Activity() {
158159
val r = try {
159160
// NB: referrer can be spoofed by the calling application. Use with caution.
160161
referrer
161-
} catch (e: RuntimeException) {
162+
} catch (_: RuntimeException) {
162163
// this could happen if the referrer intent contains data we can't deserialize
163164
return
164165
} ?: return

0 commit comments

Comments
 (0)