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

fix: properly normalize uppercase mail addresses #3330

Merged
merged 2 commits into from
Jun 21, 2023

Conversation

hperl
Copy link
Contributor

@hperl hperl commented Jun 19, 2023

Related issue(s)

Fixes #3187
Fixes #3289
Fixes ory/network#273

@hperl hperl requested a review from jonas-jonas June 19, 2023 16:18
@hperl hperl self-assigned this Jun 19, 2023
@codecov
Copy link

codecov bot commented Jun 19, 2023

Codecov Report

Merging #3330 (200e57a) into master (7182eca) will increase coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 200e57a differs from pull request most recent head c93b543. Consider uploading reports for the commit c93b543 to get more accurate results

@@           Coverage Diff           @@
##           master    #3330   +/-   ##
=======================================
  Coverage   78.11%   78.12%           
=======================================
  Files         325      325           
  Lines       21081    21085    +4     
=======================================
+ Hits        16468    16472    +4     
  Misses       3384     3384           
  Partials     1229     1229           
Impacted Files Coverage Δ
identity/extension_recovery.go 96.66% <100.00%> (+0.23%) ⬆️
identity/extension_verify.go 97.67% <100.00%> (+0.11%) ⬆️

Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

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

LGTM!

How will this affect existing addresses? Does it make sense to use SQL's ToLower like for credential identifiers?

@BrandonNoad
Copy link
Contributor

May also fix ory/network#273

@hperl
Copy link
Contributor Author

hperl commented Jun 21, 2023

May also fix ory/network#273

Indeed, putting that on the list as well!

@hperl hperl force-pushed the hperl/fix-uppercase-emails branch from 29d6c31 to c93b543 Compare June 21, 2023 07:07
@hperl
Copy link
Contributor Author

hperl commented Jun 21, 2023

LGTM!

How will this affect existing addresses? Does it make sense to use SQL's ToLower like for credential identifiers?

We already normalize the recovery and verifiable addresses on identity create and update here:

func (p *IdentityPersister) normalizeAllAddressess(ctx context.Context, identities ...*identity.Identity) {
for _, id := range identities {
p.normalizeRecoveryAddresses(ctx, id)
p.normalizeVerifiableAddresses(ctx, id)
}
}
. So in the database there should always only be lowercase recovery and verifiable addresses.

We also had a migration that made all addresses lowercase here:

UPDATE identity_recovery_addresses SET value = LOWER(value) WHERE TRUE;
UPDATE identity_verifiable_addresses SET value = LOWER(value) WHERE TRUE;

So existing addresses should be fine, as all addresses are written lowercase, and we migrated all mixedcase addresses to lowercase at some point.


Note, this fix is still necessary (or actually fixes things), because in a patch/update of an identity we get the identity from the database (with a lowercase email address), and then verify the traits to see if the verified address changed (which may be mixed case). Finally, in

func updateAssociation[T interface {
we compare the addresses by a hash to see if the value needs to be updated. Since the lowercase value from the verifiable address does not match the mixed case email from the trait, the association gets removed.

@aeneasr aeneasr merged commit eac908c into master Jun 21, 2023
21 checks passed
@aeneasr aeneasr deleted the hperl/fix-uppercase-emails branch June 21, 2023 08:31
@adamstrawson
Copy link

Thanks for such a quick turn around on this @hperl 👏

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