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

Compare lowercase email when updating from ldap #33813

Merged
merged 1 commit into from
Sep 6, 2022

Conversation

artonge
Copy link
Contributor

@artonge artonge commented Sep 1, 2022

I dug into it again, and the issue is much simpler than I previously though.

The fix is to compare the old email with the new lower case email before sending the event.

Scenario:
- Nextcloud has an email with capital letters for a user. No idea why, as it seems we are storing it in lowercases.
- LDAP has the same email address.
- The user log in, calling processAttributes, which call updateEmail, which compare emails as they are stored ($currentEmail !== $email)
- But when we are about to update the email, we once again check old and new values, but this time we lower case the new value

This means that Nextcloud will try to update the email again and again because we compare an address email with its lower case equivalent. Remember that Nextcloud has an email with capital letter in its database.
So the user will receive a continuous stream of email signaling an email change as we later compare email as they are before triggering the event.

@artonge artonge added bug 3. to review Waiting for reviews feature: ldap feature: emails php Pull requests that update Php code labels Sep 1, 2022
@artonge artonge added this to the Nextcloud 25 milestone Sep 1, 2022
@artonge artonge self-assigned this Sep 1, 2022
@artonge artonge force-pushed the fix/infinite_email_change_notification branch from 1115490 to b96c8fe Compare September 1, 2022 17:00
@blizzz blizzz mentioned this pull request Sep 1, 2022
@blizzz
Copy link
Member

blizzz commented Sep 2, 2022

If the email already is being received lowercase it should also stay lower case. I would not know why or where this change would happen. The fix will surely work, however I am not sure this is should be necessary, when the issue might be elsewhere. Could you reproduce this behaviour?

Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

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

Maybe instead fix setEMailAddress to correctly handle this usecase?
Either we support storing uppercase email and we should be able to update it. Or we do not and it should be ensured by the system.

apps/user_ldap/lib/User/User.php Outdated Show resolved Hide resolved
@blizzz blizzz mentioned this pull request Sep 6, 2022
@artonge artonge force-pushed the fix/infinite_email_change_notification branch from b96c8fe to e184d57 Compare September 6, 2022 08:58
@artonge
Copy link
Contributor Author

artonge commented Sep 6, 2022

My first analysis was wrong, I update the first comment, please review again, and thanks for the feedbacks :)

@artonge
Copy link
Contributor Author

artonge commented Sep 6, 2022

/backport to stable24

@artonge
Copy link
Contributor Author

artonge commented Sep 6, 2022

/backport to stable23

@artonge
Copy link
Contributor Author

artonge commented Sep 6, 2022

/backport to stable22

@artonge
Copy link
Contributor Author

artonge commented Sep 6, 2022

CI failure look unrelated

@artonge
Copy link
Contributor Author

artonge commented Sep 6, 2022

/rebase

@artonge
Copy link
Contributor Author

artonge commented Sep 6, 2022

Just to be sure ^

…though.

- LDAP has an email address with capital letters
- NC store this address in lower case
- When the user logs in, we compare the [stored email with the new lower case email](https://github.com/nextcloud/server/blob/master/lib/private/AllConfig.php#L259-L261) before storing it. Here, both email will be the same, so we won't store the new email address with upper case letters. Which is what we want.
- We then [compare emails as they are before triggering an event](https://github.com/nextcloud/server/blob/master/lib/private/User/User.php#L202-L204), they won't match, so the user will receive an email signaling an email change every time he logs in.

The fix is to compare the old email with the new lower case email before sending the event.

Signed-off-by: Louis Chemineau <louis@chmn.me>
@nextcloud-command nextcloud-command force-pushed the fix/infinite_email_change_notification branch from e184d57 to 6c11944 Compare September 6, 2022 13:18
@artonge artonge merged commit 1f96717 into master Sep 6, 2022
@artonge artonge deleted the fix/infinite_email_change_notification branch September 6, 2022 15:10
CarlSchwan added a commit that referenced this pull request Oct 17, 2022
Otherwise we detect a email change all the time and since email are
immutable in ldap this prevent updating other fields.

Related: #33813

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
PVince81 pushed a commit that referenced this pull request Dec 16, 2022
Otherwise we detect a email change all the time and since email are
immutable in ldap this prevent updating other fields.

Related: #33813

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
backportbot-nextcloud bot pushed a commit that referenced this pull request Dec 16, 2022
Otherwise we detect a email change all the time and since email are
immutable in ldap this prevent updating other fields.

Related: #33813

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
backportbot-nextcloud bot pushed a commit that referenced this pull request Dec 16, 2022
Otherwise we detect a email change all the time and since email are
immutable in ldap this prevent updating other fields.

Related: #33813

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
backportbot-nextcloud bot pushed a commit that referenced this pull request Dec 16, 2022
Otherwise we detect a email change all the time and since email are
immutable in ldap this prevent updating other fields.

Related: #33813

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
akhil1508 pushed a commit to e-foundation/server that referenced this pull request Dec 19, 2022
Otherwise we detect a email change all the time and since email are
immutable in ldap this prevent updating other fields.

Related: nextcloud#33813

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
@timkrueger
Copy link

The backports for 23 and 24 are still missing because they were reverted in the past:

@come-nc
Copy link
Contributor

come-nc commented Jan 2, 2023

/backport to stable23

@come-nc
Copy link
Contributor

come-nc commented Jan 2, 2023

/backport to stable24

s8321414 pushed a commit to MODAODF/odfweb that referenced this pull request May 4, 2023
Otherwise we detect a email change all the time and since email are
immutable in ldap this prevent updating other fields.

Related: nextcloud/server#33813

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3. to review Waiting for reviews bug feature: emails feature: ldap php Pull requests that update Php code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants