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

Do not serialize access tokens #1267

Merged
merged 1 commit into from
Jul 7, 2021
Merged

Conversation

LukasPaczos
Copy link
Contributor

Ensures that access tokens are not serialized in order to avoid often unintentional leaks of the data when paired with other tools and utilities that serialize and store either the whole route response, route, or only the options. Unfortunately, due to the limitations of the code generation tools used we need to make the token field nullable until we find a better solution.

I also tried upgrading the https://github.com/rharter/auto-value-gson library that is used in this project to the latest version but it didn't seem to have the features needed to support a non-nullable property that is also not serializable and initialize it externally. We can cut a feature request, contribute, or think about a different solution in the future.

@LukasPaczos LukasPaczos requested a review from a team June 29, 2021 16:56
* @return a new instance of this class defined by the values passed inside this static factory
* method
* @see #fromUrl(URL)
*/
@NonNull
public static RouteOptions fromJson(String json) {
public static RouteOptions fromJson(@NonNull String json, @Nullable String accessToken) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just to clarify, is this method used anywhere except tests?
will we always have accessToken=null in the DirectionsResponse ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a utility so that devs don't need to do fromJson.toBuilder.accessToken.build and it's clear that accessToken needs to be provided again, it's not serialized.

@Guardiola31337
Copy link
Contributor

I also tried upgrading the https://github.com/rharter/auto-value-gson library that is used in this project to the latest version but it didn't seem to have the features needed to support a non-nullable property that is also not serializable and initialize it externally. We can cut a feature request, contribute, or think about a different solution in the future.

@rharter First of all, thanks for the great library! Do you know off the top of your head if above is possible with some workaround or if not if would be feasible and how big of a lift would be? We're going to create a ticket in https://github.com/rharter/auto-value-gson but wanted to hear your initial thoughts first as creator of the extension. Looking forward to hearing from you. Thanks again! 🙇‍♂️

@LukasPaczos LukasPaczos force-pushed the lp-dont-serialize-access-tokens branch from 24c9a90 to 6c54ab3 Compare July 6, 2021 17:38
Ensures that access tokens are not serialized in order to avoid often unintentional leaks of the data when paired with other tools and utilities that serialize and store either the whole route response, route, or only the options. Unfortunately, due the limitations of the code generation tools used we need to make the token field nullable until we find a better solution.
@LukasPaczos LukasPaczos force-pushed the lp-dont-serialize-access-tokens branch from 6c54ab3 to 24f64a2 Compare July 6, 2021 17:44
Gson gson = new Gson();
JsonObject object = gson.fromJson(json, JsonObject.class);

Assert.assertNull(object.get("access_token"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT

Suggested change
Assert.assertNull(object.get("access_token"));
assertNull(object.get("access_token"));

@rharter
Copy link

rharter commented Jul 7, 2021

I don't have any specific approaches to solve the problem above. It sounds like the desire is really to have AVG deserialize a populated builder that the user can then provide an access token to, since you wouldn't be able to deserialize a valid object with a missing, but non-nullable, property. Offhand that would be my first inclination. The above suggested API looks good to me, internally the fromJson method could just deserialize a package private object like a builder and construct the route options by combining that with the provided token.

@LukasPaczos LukasPaczos merged commit 169d0e0 into main Jul 7, 2021
@LukasPaczos LukasPaczos deleted the lp-dont-serialize-access-tokens branch July 7, 2021 12:42
@LukasPaczos
Copy link
Contributor Author

Thanks for chiming in @rharter! The idea of deserializing into an intermediate, private structure gave me the idea to deserialize into a generic JsonObject first, append the token, and then transform the structure into the proper target object. This is not as safe as a dedicated structure but offers the same functionality with hopefully smaller maintenance needs. Up for discussion in #1270.

@Guardiola31337
Copy link
Contributor

Thanks a lot @rharter for your input. Really appreciate it 🙇‍♂️

As @LukasPaczos mentioned take a look at #1270 if you're curious about the solution we opted for 🚀

Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants