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

feat: Add new Parse Server option preventSignupWithUnverifiedEmail to prevent returning a user without session token on sign-up with unverified email address #8451

Merged
merged 12 commits into from
Jun 7, 2023

Conversation

dblythy
Copy link
Member

@dblythy dblythy commented Mar 2, 2023

Pull Request

Issue

Current, when using preventLoginWithUnverifiedEmail, the save response is a 201, and the JS SDK assigns Parse.User.current() with an objectId, but no session token. Instead, the same response should return as a login, which is:

new Parse.Error(Parse.Error.EMAIL_NOT_FOUND, 'User email is not verified.')

Closes: #2863

Approach

All other operations should occur, just the response should throw. There will need to be some refactoring, as currently the feature is implemented as:

await user.signup();
await user.logout();
// we've sent you an email, please verify your email to continue

New:

try {
  await user.signup();
} catch (e) {
  if (e.code === Parse.Error.EMAIL_NOT_FOUND) {
     // we've sent you an email, please verify your email to continue
  }
}

Perhaps we could add an option to the JS SDK signup method such as {login: false} that can determine whether signup can throw User email is not verified

Tasks

  • Add tests

@parse-github-assistant
Copy link

I will reformat the title to use the proper commit message syntax.

@parse-github-assistant parse-github-assistant bot changed the title fix: reject signup with preventLoginWithUnverifiedEmail fix: Reject signup with preventLoginWithUnverifiedEmail Mar 2, 2023
@parse-github-assistant
Copy link

Thanks for opening this pull request!

@codecov
Copy link

codecov bot commented Mar 2, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: -0.15 ⚠️

Comparison is base (0ce3692) 94.34% compared to head (d5b4757) 94.19%.

❗ Current head d5b4757 differs from pull request most recent head 18b920d. Consider uploading reports for the commit 18b920d to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##            alpha    #8451      +/-   ##
==========================================
- Coverage   94.34%   94.19%   -0.15%     
==========================================
  Files         183      183              
  Lines       14576    14579       +3     
==========================================
- Hits        13751    13732      -19     
- Misses        825      847      +22     
Impacted Files Coverage Δ
src/Options/Definitions.js 100.00% <ø> (ø)
src/Options/index.js 100.00% <ø> (ø)
src/RestWrite.js 94.96% <100.00%> (+0.02%) ⬆️

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@dblythy dblythy requested a review from a team March 5, 2023 01:03
@mtrezza
Copy link
Member

mtrezza commented Mar 6, 2023

Currently the response is 201 success and with the PR the response will be a 400 error? Isn't that a breaking change?

@dblythy
Copy link
Member Author

dblythy commented Mar 6, 2023

Is it considered a breaking change if it's a bug in the expected behaviour?

@mtrezza
Copy link
Member

mtrezza commented Mar 7, 2023

There's no fixed rule. Generally, if it's incorrect behavior but the feature is usable, then we can assume developers found a workaround. Breaking that workaround would make it a breaking change, even if it's just correcting the incorrect behavior. If there is no practical workaround then it's not a breaking change. If the bug exists only in an alpha or beta pre-release then it's also not a breaking change, because we can fix that before official release. For security fixes there are other additional considerations.

Here, if the http response code is 201 instead of 400, and developers work around this by checking for an existing session token, then I guess it would be breaking. Technically it should be 400, but with some imagination one could say it can be 201 because an object ID is assigned, there's just no session token. What do you think?

I guess a simple test is always to imagine your own app is using the feature and depending on the status quo. Then you upgrade Parse Server and millions of clients expecting hard-codedly a 201 response will suddenly break. Would you have wanted this to be communicated as a breaking change?

@dblythy
Copy link
Member Author

dblythy commented Mar 7, 2023

It is a breaking change, so should we wait for a major release? How do you think we should approach this?

If we leave it as a status 200, but return a response with no session token, the client SDKs will think the login was successful, assign a Parse.User with no session token, and future requests will fail with cannot modify user. This is the current status-quo of the feature:

 const user = new Parse.User();
user.setPassword('asdf');
user.setUsername('zxcv');
user.set('email', 'testInvalidConfig@example.com');
await user.signUp(null);
console.log(Parse.User.current()) // is defined
user.set('foo', 'bar');
await user.save(); // cannot modify user

The current work around is:

 const user = new Parse.User();
user.setPassword('asdf');
user.setUsername('zxcv');
user.set('email', 'testInvalidConfig@example.com');
await user.signUp(null);
await Parse.User.logOut()

@mtrezza
Copy link
Member

mtrezza commented Mar 7, 2023

If we say this is breaking then we can

  • leave as it until next major release, or
  • add a server option with a deprecation that can released immediately as feature release

The challenge with this correction is that it's not just server side code that needs to be updated, but possibly clients. That often mans a long-winding migration process over +1 year. So we could:

  • Add an option to allow developers to switch to the correct behavior immediately.
  • In Jan 2024 with Parse Server 7 we can change the option default to the correct behavior, and deprecate the option, so developers are informed that they have 1 year to migrate.
  • In Jan 2025 with Parse Server 8 we can remove the option, unless we get feedback that more time is needed to migrate.

@dblythy
Copy link
Member Author

dblythy commented Mar 29, 2023

Refactored this to be a Parse Server option: preventSignupWithUnverifiedEmail

@dblythy dblythy changed the title fix: Reject signup with preventLoginWithUnverifiedEmail feat: Reject signup with preventSignupWithUnverifiedEmail Mar 29, 2023
Copy link
Member

@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.

I've added some more details to the option docs. Could you check whether I got this right and rebuild the definitions?

src/Options/index.js Outdated Show resolved Hide resolved
@mtrezza mtrezza changed the title feat: Reject signup with preventSignupWithUnverifiedEmail feat: Add new Parse Server option preventSignupWithUnverifiedEmail to reject sign-up with unverified email address May 18, 2023
@mtrezza mtrezza changed the title feat: Add new Parse Server option preventSignupWithUnverifiedEmail to reject sign-up with unverified email address feat: Add new Parse Server option preventSignupWithUnverifiedEmail to prevent creating a user without session token on sign-up with unverified email address May 18, 2023
@mtrezza mtrezza changed the title feat: Add new Parse Server option preventSignupWithUnverifiedEmail to prevent creating a user without session token on sign-up with unverified email address feat: Add new Parse Server option preventSignupWithUnverifiedEmail to prevent returning a user without session token on sign-up with unverified email address May 18, 2023
@mtrezza
Copy link
Member

mtrezza commented May 18, 2023

The new PR title is somewhat long, but I thought "prevent sign-up with unverified email" sounds strange because an email address is always unverified on sign-up.

dblythy and others added 3 commits June 8, 2023 00:11
Co-authored-by: Manuel <5673677+mtrezza@users.noreply.github.com>
Signed-off-by: Daniel <daniel-blyth@live.com.au>
@dblythy
Copy link
Member Author

dblythy commented Jun 7, 2023

Sounds good to me!

Copy link
Member

@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.

Looks good, is this ready for merge?

@dblythy
Copy link
Member Author

dblythy commented Jun 7, 2023

Yep!

@mtrezza mtrezza merged commit 82da308 into parse-community:alpha Jun 7, 2023
parseplatformorg pushed a commit that referenced this pull request Jun 7, 2023
# [6.1.0-alpha.17](6.1.0-alpha.16...6.1.0-alpha.17) (2023-06-07)

### Features

* Add new Parse Server option `preventSignupWithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.1.0-alpha.17

@parseplatformorg parseplatformorg added the state:released-alpha Released as alpha version label Jun 7, 2023
parseplatformorg pushed a commit that referenced this pull request Jun 10, 2023
# [6.3.0-beta.1](6.2.0...6.3.0-beta.1) (2023-06-10)

### Bug Fixes

* Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515))
* GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b))
* Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02))
* LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b))
* Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c))
* Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007))

### Features

* `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3))
* Add new Parse Server option `preventSignupWithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308))
* Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31))
* Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673))
* Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97))
* Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3))

### Reverts

* fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.3.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Jun 10, 2023
parseplatformorg pushed a commit that referenced this pull request Jun 18, 2023
# [6.3.0-alpha.1](6.2.0...6.3.0-alpha.1) (2023-06-18)

### Bug Fixes

* Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515))
* GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b))
* Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02))
* LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b))
* Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c))
* Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007))

### Features

* `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3))
* Add new Parse Server option `preventSignupWithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308))
* Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31))
* Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673))
* Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97))
* Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3))

### Reverts

* fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.3.0-alpha.1

parseplatformorg pushed a commit that referenced this pull request Sep 16, 2023
# [6.3.0](6.2.2...6.3.0) (2023-09-16)

### Bug Fixes

* Cloud Code Trigger `afterSave` executes even if not set ([#8520](#8520)) ([afd0515](afd0515))
* GridFS file storage doesn't work with certain `enableSchemaHooks` settings ([#8467](#8467)) ([d4cda4b](d4cda4b))
* Inaccurate table total row count for PostgreSQL ([#8511](#8511)) ([0823a02](0823a02))
* LiveQuery server is not shut down properly when `handleShutdown` is called ([#8491](#8491)) ([967700b](967700b))
* Rate limit feature is incompatible with Node 14 ([#8578](#8578)) ([f911f2c](f911f2c))
* Unnecessary log entries by `extendSessionOnUse` ([#8562](#8562)) ([fd6a007](fd6a007))

### Features

* `extendSessionOnUse` to automatically renew Parse Sessions ([#8505](#8505)) ([6f885d3](6f885d3))
* Add new Parse Server option `preventSignupWithUnverifiedEmail` to prevent returning a user without session token on sign-up with unverified email address ([#8451](#8451)) ([82da308](82da308))
* Add option to change the log level of logs emitted by Cloud Functions ([#8530](#8530)) ([2caea31](2caea31))
* Add support for `$eq` query constraint in LiveQuery ([#8614](#8614)) ([656d673](656d673))
* Add zones for rate limiting by `ip`, `user`, `session`, `global` ([#8508](#8508)) ([03fba97](03fba97))
* Allow `Parse.Object` pointers in Cloud Code arguments ([#8490](#8490)) ([28aeda3](28aeda3))

### Reverts

* fix: Inaccurate table total row count for PostgreSQL ([6722110](6722110))
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 6.3.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Sep 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-alpha Released as alpha version state:released-beta Released as beta version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

preventLoginWithUnverifiedEmail not Working
3 participants