Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protect the app from importing keys and values that are not supported according to the json scheme #5154

Merged
merged 18 commits into from
Jul 12, 2022

Conversation

grzesiek2010
Copy link
Member

@grzesiek2010 grzesiek2010 commented May 31, 2022

Closes #5096
Closes #4939
Closes #5176

What has been done to verify that this works as intended?

I've tested the app manually and improved automated tests.

Why is this the best possible solution? Were any other approaches considered?

I've extended JsonSchemaSettingsValidator and added methods to verify if existing keys/values are supported.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Please verify the case form the issue #5096

Do we need any specific form for testing your changes? If so, please attach one.

No.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

No.

Before submitting this PR, please make sure you have:

  • run ./gradlew checkAll and confirmed all checks still pass OR confirm CircleCI build passes and run ./gradlew connectedDebugAndroidTest locally.
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

@grzesiek2010 grzesiek2010 changed the title Collect 5096 Protect the app from importing keys and values that are not supported according to the json scheme May 31, 2022
@grzesiek2010 grzesiek2010 marked this pull request as ready for review May 31, 2022 16:54
@lognaturel lognaturel requested a review from seadowg June 21, 2022 14:45
@seadowg
Copy link
Member

seadowg commented Jun 28, 2022

@grzesiek2010 is this meant to close #4939?

@grzesiek2010
Copy link
Member Author

@grzesiek2010 is this meant to close #4939?

Yes, I've just fixed the description.

settings/build.gradle Outdated Show resolved Hide resolved
@dbemke
Copy link

dbemke commented Jul 7, 2022

Tested with Success!

Verified on Android 8.1, 11

Verified cases:

@srujner
Copy link

srujner commented Jul 7, 2022

Tested with Success!

Verified on Android 10 and 12

Today I found one strange issue related to Android 5.1 only: #5178

@grzesiek2010
Copy link
Member Author

grzesiek2010 commented Jul 7, 2022

@seadowg there are new changes (for #5176) here so you might want to take a look.

In the issue @lognaturel asked if #5176 is a fix for this Crashlytics report. I said that the issue was probably responsible for just a part of the reports.
Now I'm thinking more about those crashes and I think that it might be caused by similar problems with QR codes that we are not able to detect and our scheme validator also does not deal with.

I wanted to propose one additional improvements which is wrapping this into try-catch and catch anything there. My thinking is that the mentioned method consists of many steps that could potentialy fail (for example creating JSONObjects).
If that method somehow throws an exception we end up with that problem with no project id. So although we do not now for sure what might throw such exceptions it seeps to be possible.

What do you think @seadowg @lognaturel?

@seadowg
Copy link
Member

seadowg commented Jul 8, 2022

I wanted to propose one additional improvements which is wrapping this into try-catch and catch anything there. My thinking is that the mentioned method consists of many steps that could potentialy fail (for example creating JSONObjects).
If that method somehow throws an exception we end up with that problem with no project id. So although we do not know for sure what might throw such exceptions it seeps to be possible.

This probably makes sense. I think we'd also want to clear the new shared preferences bucket in the catch as well. A potentially nicer alternative would be to wrap ProjectCreator#createNewProject's implementation in a "catch all" try-catch (and perform project repo/shared prefs clean up in the catch). Then we could remove the try-catch at QrCodeProjectCreatorDialog#createProjectOrError and just show an error when createNewProject returns false (which simplifies our UI code).

@grzesiek2010
Copy link
Member Author

A potentially nicer alternative would be to wrap ProjectCreator#createNewProject's implementation in a "catch all" try-catch (and perform project repo/shared prefs clean up in the catch). Then we could remove the try-catch at QrCodeProjectCreatorDialog#createProjectOrError and just show an error when createNewProject returns false (which simplifies our UI code).

I already removed try-catch from QrCodeProjectCreatorDialog#createProjectOrError in this pr.
I think we should rather use try-catch in ODKAppSettingsImporter#fromJSON because this methods is the only place where SettingsImporter.fromJSON (the risky one) is called but ODKAppSettingsImporter#fromJSON itself is called from different places so i think it should catch exceptions and return false.

Then in ProjectCreator#createNewProject we can delete project / clear prefs if the returned value is false.

What do you think?

@seadowg
Copy link
Member

seadowg commented Jul 8, 2022

@grzesiek2010 ah sorry I just realized I was looking at the current master. Yeah, that sounds good!

@grzesiek2010 grzesiek2010 requested a review from seadowg July 8, 2022 12:50
@grzesiek2010
Copy link
Member Author

@seadowg new changes have been added. Please review.

@grzesiek2010 grzesiek2010 merged commit 2b824ba into getodk:master Jul 12, 2022
@grzesiek2010 grzesiek2010 mentioned this pull request Jul 13, 2022
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants