Sanitize external intents
We don't currently sanitize intents correctly, see https://bugzilla.mozilla.org/show_bug.cgi?id=1759760#c3
┆Issue is synchronized with this Jira Task
As Christian mentioned, any call to putExtra will trigger a unparcel call which will try to de-serialize the extras for the intent. In particular for the crash of this bug, I believe this is the call site: https://searchfox.org/mozilla-mobile/rev/a351ac688572593698d62a7e42feb9992a205412/focus-android/app/src/main/java/org/mozilla/focus/activity/IntentReceiverActivity.kt#51
The documentation mentions this:
Sending data between processes is similar to doing so between activities. However, when sending between processes, we recommend that you do not use custom parcelables. If you send a custom Parcelable object from one app to another, you need to be certain that the exact same version of the custom class is present on both the sending and receiving apps. Typically this could be a common library used across both apps. An error can occur if your app tries to send a custom parcelable to the system, because the system cannot unmarshal a class that it has no knowledge of.
https://developer.android.com/guide/components/activities/parcelables-and-bundles
Chrome handles this by requesting a non-existent key and catching the exception:
public static Intent sanitizeIntent(final Intent incomingIntent) {
if (incomingIntent == null) return null;
try {
incomingIntent.getBooleanExtra("TriggerUnparcel", false);
return incomingIntent;
} catch (BadParcelableException e) {
return logInvalidIntent(incomingIntent, e);
} catch (RuntimeException e) {
if (e.getCause() instanceof ClassNotFoundException) {
return logInvalidIntent(incomingIntent, e);
}
throw e;
}
}
https://source.chromium.org/chromium/chromium/src/+/main:base/android/java/src/org/chromium/base/IntentUtils.java;l=481-494;drc=48a3eaf6f8ae83f7c99851f0b9088365e3edf6e6
Chrome handles this by requesting a non-existent key and catching the exception:
And strip out extras: https://source.chromium.org/chromium/chromium/src/+/main:base/android/java/src/org/chromium/base/IntentUtils.java;l=473;drc=6543aa92b297f25a1c67be7fad5741ab34a1762d