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

Throw error when setting authData to null #6154

Merged
merged 16 commits into from
Oct 28, 2019

Conversation

mtrezza
Copy link
Member

@mtrezza mtrezza commented Oct 23, 2019

Fixed authData field in DB overwriting synthesized authData field that contains values of _auth_data_* fields.

Fixed only for mongoDB & Postgres.

@dplewis
Copy link
Member

dplewis commented Oct 23, 2019

Looks good. Can you add a test case?

@codecov
Copy link

codecov bot commented Oct 23, 2019

Codecov Report

Merging #6154 into master will decrease coverage by <.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #6154      +/-   ##
==========================================
- Coverage   93.76%   93.75%   -0.01%     
==========================================
  Files         166      166              
  Lines       11271    11291      +20     
==========================================
+ Hits        10568    10586      +18     
- Misses        703      705       +2
Impacted Files Coverage Δ
src/Adapters/Storage/Mongo/MongoTransform.js 88.67% <100%> (+0.21%) ⬆️
src/RestWrite.js 93.42% <100%> (-0.48%) ⬇️
src/Routers/FilesRouter.js 92.72% <0%> (-0.26%) ⬇️
src/Adapters/Files/FilesAdapter.js 100% <0%> (ø) ⬆️
src/ParseServer.js 97.59% <0%> (+0.05%) ⬆️
src/Adapters/Files/GridFSBucketAdapter.js 68.85% <0%> (+0.51%) ⬆️
src/Controllers/FilesController.js 93.02% <0%> (+0.52%) ⬆️
src/Adapters/Files/GridStoreAdapter.js 46.37% <0%> (+0.78%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac4d9ed...a02fcd2. Read the comment docs.

@mtrezza
Copy link
Member Author

mtrezza commented Oct 23, 2019

Actually it would be better to test this on a higher level instead of MongoTransform, so the test would be automatically done for mongoDB and Postgres, right?

@dplewis
Copy link
Member

dplewis commented Oct 23, 2019

Yes, a REST call will work. I’ll do some additional testing on my end.

@mtrezza
Copy link
Member Author

mtrezza commented Oct 23, 2019

Added a test on ParseUser that reproduces the exact same error:

image

spec/ParseUser.spec.js Outdated Show resolved Hide resolved
@mtrezza
Copy link
Member Author

mtrezza commented Oct 23, 2019

Is there a way I can easily execute the test locally with Postgres? I only see the failing tests once I update the PR.

@dplewis
Copy link
Member

dplewis commented Oct 23, 2019

@dplewis dplewis closed this Oct 23, 2019
@dplewis dplewis reopened this Oct 23, 2019
@dplewis dplewis requested a review from acinader October 27, 2019 02:58
@dplewis
Copy link
Member

dplewis commented Oct 27, 2019

@mtrezza @acinader Instead of ignoring should we throw and error similar to user.unset('authData').

The goal here is to prevent directly manipulating authData in favor of unlink and link

@mtrezza
Copy link
Member Author

mtrezza commented Oct 27, 2019

@dplewis Good point, throwing would create more awareness that there is something wrong than ignoring. Currently the server has an uncaught internal exception, so the benefit of this PR would be a proper error description.

Sent with GitHawk

@dplewis
Copy link
Member

dplewis commented Oct 27, 2019

@mtrezza @acinader How does this look?

@dplewis dplewis changed the title added ignore authData field Throw error when setting authData to null Oct 27, 2019
@mtrezza
Copy link
Member Author

mtrezza commented Oct 27, 2019

@dplewis

  • can’t see properly on mobile, but does this only throw for auth in _User class? Should be allowed for other classes.
  • appears to me that the changes correctly disallow setting authData, but an existing authData field in the _User class will again throw an uncaught internal exception. So how about adding those cases again and throwing when there’s an authData field?

Sent with GitHawk

@dplewis
Copy link
Member

dplewis commented Oct 27, 2019

does this only throw for auth in _User class?

Yes here checks if user class or not

an existing authData field in the _User class will again throw

I don't believe it will throw again. This is a fail fast solution, doesn't matter what's in the DB. Can you write a failing test just in case?

@mtrezza
Copy link
Member Author

mtrezza commented Oct 27, 2019

@dplewis The test you removed from MongoTransform would be the failing test. Can you try with that enabled? I believe it will fail. The issue was that in the transform, the authData field from the DB overwrites the synthesized authData field for the User object. So I believe we should add the case again and throw right there in the tranform for Mongo and Postgres.

If that doesn’t make much sense I can add the changes when I’m not on mobile.

Regarding backwards compatibility, I believe it wouldn’t be worse than the current internal server exception if we throw there.

Sent with GitHawk

@dplewis
Copy link
Member

dplewis commented Oct 27, 2019

@mtrezza Oh I get what you are saying. My fix prevents setting authData. Your fix checks if authData field already exists and prevents it from overriding.

@mtrezza
Copy link
Member Author

mtrezza commented Oct 27, 2019

@dplewis Correct, I believe adding both makes sense. We could also ignore and log a warning when authData exists. Is that something we usually do for that level of severity?

Sent with GitHawk

@dplewis
Copy link
Member

dplewis commented Oct 27, 2019

@mtrezza I added back your changes and wrote more tests.

@mtrezza
Copy link
Member Author

mtrezza commented Oct 28, 2019

@dplewis I think we are getting close :)

Copy link
Contributor

@acinader acinader left a comment

Choose a reason for hiding this comment

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

this looks good.

src/Adapters/Storage/Mongo/MongoTransform.js Show resolved Hide resolved
Copy link
Member Author

@mtrezza mtrezza left a comment

Choose a reason for hiding this comment

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

(fighting with the review feature)

src/Adapters/Storage/Mongo/MongoTransform.js Show resolved Hide resolved
@dplewis dplewis merged commit 9d781c4 into parse-community:master Oct 28, 2019
@dplewis
Copy link
Member

dplewis commented Oct 28, 2019

@mtrezza Nice working with you, we should do this again sometime. 👍

@mtrezza
Copy link
Member Author

mtrezza commented Oct 28, 2019

@dplewis I agree, was my pleasure.

@mtrezza mtrezza deleted the fix-crash-on-invalid-authData branch October 28, 2019 01:46
UnderratedDev pushed a commit to UnderratedDev/parse-server that referenced this pull request Mar 21, 2020
* added ignore authData field

* add fix for Postgres

* add test for mongoDB

* add test login with provider despite invalid authData

* removed fit

* fixed ignoring authData in postgres

* Fix postgres test

* Throw error instead of ignore

* improve tests

* Add mongo test

* allow authData when not user class

* fix tests

* more tests

* add condition to synthesize authData field only in _User class

it is forbidden to add a custom field name beginning with `_`, so if the object is not `_User` , the transform should throw

* add warning log when ignoring invalid `authData` in `_User`

* add test to throw when custom field begins with underscore
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.

3 participants