Skip to content

🐛 Bug Report: Error 500 using updateEmail when password is not set cause OAuth2 #4975

Closed

Description

@gepd

👟 Reproduction steps

  1. Authenticate with any OAuth2 provider
  2. try to update the email or phone using the updateEmail or updatePhone endpoint

👍 Expected behavior

Update the email or phone without ask for a password, or use other method to confirm the changes

👎 Actual Behavior

We get an error

Unhandled Runtime Error
AppwriteException: Server Error

I have test it with updateEmail and updatePhone but this should happen in any endpoint who requires a password

the container logs shows the following error:

[Error] Method: PATCH
[Error] URL: /v1/account/phone
[Error] Type: TypeError
[Error] Message: Appwrite\Auth\Auth::passwordVerify(): Argument #2 ($hash) must be of type string, null given, called in /usr/src/code/app/controllers/api/account.php on line 1569
[Error] File: /usr/src/code/src/Appwrite/Auth/Auth.php
[Error] Line: 216

🎲 Appwrite version

Version 1.2.x

💻 Operating system

Linux

🧱 Your Environment

No response

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Activity

  1. added
    bug
    on Jan 9, 2023
  2. AkashSharma001 commented on Jan 9, 2023

    @AkashSharma001

    I would like to work on this. @stnguyen90

  3. harshmange44 commented on Jan 9, 2023

    @harshmange44

    Hey, I would like to fix this @gepd @stnguyen90

  4. added
    product / auth
    on Jan 10, 2023
  5. stnguyen90 commented on Jan 10, 2023

    @stnguyen90
    Contributor

    @gepd, would you please provide the docker logs for the appwrite container related to this error?

  6. self-assigned this
    on Jan 10, 2023
  7. gepd commented on Jan 10, 2023

    @gepd
    ContributorAuthor

    Sure! @stnguyen90 I have updated the issue with the info

  8. stnguyen90 commented on Jan 10, 2023

    @stnguyen90
    Contributor

    @gepd thanks! let me check with the team to see how we want Appwrite to behave for this.

  9. gepd commented on Jan 10, 2023

    @gepd
    ContributorAuthor

    I didn't realize, this is caused for a different reason in my case; the user is using an OAuth2 authentication that is why there is not password set.

    Isn't possible to this happen with email and password authentication as, for use any of that endpoint first you need to have an active session and as the user haven't a password, the session can't be created

    I think this problem can happen with any other password less authentication method when the user doesn't have set a password

  10. changed the title [-]🐛 Bug Report: Error 500 using `updateEmail|updatePhone` when password is not set[/-] [+]🐛 Bug Report: Error 500 using `updateEmail` when password is not set cause OAuth2[/+] on Jan 10, 2023
  11. gepd commented on Jan 17, 2023

    @gepd
    ContributorAuthor

    @stnguyen90 did you get any answer from the team?

  12. stnguyen90 commented on Feb 23, 2023

    @stnguyen90
    Contributor

    @gepd, sorry I missed this! we discussed this internally, and we have decided we:

    1. shouldn't do any validation before updating email or phone if the user doesn't have a password
    2. shouldn't set the password with what was passed in if the user doesn't have a password
  13. stnguyen90 commented on Feb 23, 2023

    @stnguyen90
    Contributor

    Possibly related: #4990

  14. removed their assignment
    on Feb 23, 2023
  15. gepd commented on Feb 24, 2023

    @gepd
    ContributorAuthor

    To do this, we should skip the validation in this 3 endpoints

    if (!empty($user->getAttribute('passwordUpdate')) && !Auth::passwordVerify($oldPassword, $user->getAttribute('password'), $user->getAttribute('hash'), $user->getAttribute('hashOptions'))) { // Double check user password

    !Auth::passwordVerify($password, $user->getAttribute('password'), $user->getAttribute('hash'), $user->getAttribute('hashOptions'))

    !Auth::passwordVerify($password, $user->getAttribute('password'), $user->getAttribute('hash'), $user->getAttribute('hashOptions'))

    I can send a PR to fix this, what do you think?

  16. stnguyen90 commented on Mar 1, 2023

    @stnguyen90
    Contributor

    @gepd, assigned!

  17. self-assigned this
    on May 25, 2023
  18. added this to the 1.4.0 milestone on May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

buggood first issueproduct / auth

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions