From 43857495b3da2c99e5ee51f0a52e51bc3d55f9d8 Mon Sep 17 00:00:00 2001 From: Son NK <> Date: Wed, 7 Oct 2020 17:57:02 +0200 Subject: [PATCH] suggestion --- app/dashboard/views/custom_alias.py | 40 ++++++++++------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/app/dashboard/views/custom_alias.py b/app/dashboard/views/custom_alias.py index 30880a73..e09e28bd 100644 --- a/app/dashboard/views/custom_alias.py +++ b/app/dashboard/views/custom_alias.py @@ -174,35 +174,23 @@ def verify_prefix_suffix(user, alias_prefix, alias_suffix) -> bool: # make sure alias_suffix is either .random_word@simplelogin.co or @my-domain.com alias_suffix = alias_suffix.strip() - if alias_suffix.startswith("@"): - alias_domain = alias_suffix[1:] - # alias_domain can be either custom_domain or if DISABLE_ALIAS_SUFFIX, one of the default ALIAS_DOMAINS - if DISABLE_ALIAS_SUFFIX: - if ( - alias_domain not in user_custom_domains - and alias_domain not in ALIAS_DOMAINS - ): - LOG.exception("wrong alias suffix %s, user %s", alias_suffix, user) - return False - else: - if alias_domain not in user_custom_domains: - LOG.exception("wrong alias suffix %s, user %s", alias_suffix, user) - return False - else: - if not alias_suffix.startswith("."): + # alias_domain_prefix is either a .random_word or "" + alias_domain_prefix, alias_domain = alias_suffix.split("@", 1) + + # alias_domain must be either one of user custom domains or built-in domains + if alias_domain not in user_custom_domains and alias_domain not in ALIAS_DOMAINS: + LOG.exception("wrong alias suffix %s, user %s", alias_suffix, user) + return False + + # built-in domain case: + # 1) alias_suffix must start with "." and + # 2) alias_domain_prefix must come from the word list + if alias_domain in ALIAS_DOMAINS and alias_domain not in user_custom_domains: + if not alias_domain_prefix.startswith("."): LOG.exception("User %s submits a wrong alias suffix %s", user, alias_suffix) return False - full_alias = alias_prefix + alias_suffix - if not email_belongs_to_alias_domains(full_alias): - LOG.exception( - "Alias suffix should end with one of the alias domains %s", - user, - alias_suffix, - ) - return False - - random_word_part = alias_suffix[1 : alias_suffix.find("@")] + random_word_part = alias_domain_prefix[1:] if not word_exist(random_word_part): LOG.exception( "alias suffix %s needs to start with a random word, user %s",