Be strict about similar email addresses for alerts

We don’t want a single person to have two accounts on an emergency
alerts service because it would let them circumvent the two eyes
approval process.

We can go some way to mitigating against this by stopping people using
common methods that email providers use to alias email addresses. These
are:
- being case insensitive
- being insensitive to the position or number of dots in the local part
  of an email address
- using ‘plus addressing’

We already prevent the first one, this commit adds normalisation which
strip out the second two before doing the comparision with the current
user’s email address.
This commit is contained in:
Chris Hill-Scott
2021-07-13 15:26:19 +01:00
parent 9dd5c89252
commit c3091223a9
3 changed files with 80 additions and 0 deletions

View File

@@ -66,3 +66,14 @@ def _email_address_ends_with(email_address, known_domains):
))
for known in known_domains
)
def normalise_email_address_aliases(email_address):
local_part, domain = email_address.split('@')
local_part = local_part.split('+')[0].replace('.', '')
return f'{local_part}@{domain}'.lower()
def distinct_email_addresses(*args):
return len(args) == len(set(map(normalise_email_address_aliases, args)))