From dc5f08ba1c5613ee8001e27ffb2952e3dcedb5b7 Mon Sep 17 00:00:00 2001 From: Clanky Date: Mon, 13 Apr 2026 07:39:47 +0300 Subject: [PATCH] update email validation regex email validation check --- auth_backend/auth_plugins/email.py | 35 +++++------------------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/auth_backend/auth_plugins/email.py b/auth_backend/auth_plugins/email.py index abf0b3c2..5fe1aedb 100644 --- a/auth_backend/auth_plugins/email.py +++ b/auth_backend/auth_plugins/email.py @@ -1,5 +1,6 @@ import hashlib import logging +import re from typing import Annotated, Self from annotated_types import MinLen @@ -26,38 +27,12 @@ settings = get_settings() logger = logging.getLogger(__name__) +EMAIL_CONST_REGEX = re.compile( + r'^[a-zA-Z0-9_.+\-%]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$') def check_email(v): - restricted: set[str] = { - '"', - '#', - '&', - "'", - '(', - ')', - '*', - ',', - '/', - ';', - '<', - '>', - '?', - '[', - '\\', - ']', - '^', - '`', - '{', - '|', - '}', - '~', - '\n', - '\r', - } - if "@" not in v: - raise ValueError() - if set(v) & restricted: - raise ValueError() + if not EMAIL_REGEX.match(v): + raise ValueError("Неверный формат email") return v