Sanitize intents in BrowserActivity #1101
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Task/Issue URL: #953
Tech Design URL:
CC:
Description:
This issue happened because every time an intent.getX (X being string, bool, etc) was called, internally it would eventually call unparcel() on BaseBundle, and if there is a class that was passed somewhere on the intent that duckduckgo can't unserialize (either by Serializable or Parcelable) it would throw an exception and close the app. One thing to note is that I tracked all current calls of where the app received intents that were not under the app control, and it seems that this point is in BrowserActivity in onNewIntent. So before any call could be made to any intent
getSomethingcall I called sanitize, which is the preferred design that duckduckgo team mentioned on the original issue URL.I think it seems safe but may require further tests since the app is quite big and there may be corner cases, one design issue though is that every new addition to the app that handle intents would have to be checked (say if for some reason another Activity that handles outside intents would be added, someone will need to remember to add
sanitize()in there). If you guys want extra control and futureproofing then maybe creating an extension method that gets extras and uses generics. So instead of using getBoolean, getString, getShort we could create a getSafe with generics and inside the method handle each case. This seems safer but it would require to refactor the entire app, but it could be enforced on future development to only use this extension method. Idk what's the best solution, it would be interesting to hear what you guys think about it.Steps to test this PR:
Internal references:
Software Engineering Expectations
Technical Design Template