From cb819a18dfa9b71b8553865b1ba0a387a6f92938 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Gastinel?= <264859180+gastinelt@users.noreply.github.com> Date: Fri, 6 Nov 2026 16:31:20 +0100 Subject: [PATCH] =?UTF-8?q?forum=20:=20usernames=20limit=C3=A9s=20aux=20le?= =?UTF-8?q?ttres=20latines=20et=20chiffres=20(bloque=20les=20sosies=20cyri?= =?UTF-8?q?lliques=20et=20grecs)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 5.5 --- forum/profil.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/forum/profil.py b/forum/profil.py index 9ffa5ba..6a12452 100644 --- a/forum/profil.py +++ b/forum/profil.py @@ -35,6 +35,13 @@ class UsernameInvalide(ValueError): _LEET = str.maketrans({"0": "o", "1": "i", "3": "e", "4": "a", "5": "s", "7": "t", "@": "a", "$": "s", "!": "i"}) +def _latin_ou_chiffre(c): + """Chiffre 0-9 ou lettre de l'alphabet latin (accents compris) : bloque les sosies cyrilliques ou grecs.""" + if "0" <= c <= "9": + return True + return c.isalpha() and unicodedata.name(c, "").startswith("LATIN ") + + def cle(texte): """Minuscules, sans accents, lettres et chiffres seulement (séparateurs retirés).""" s = unicodedata.normalize("NFKD", (texte or "").casefold()) @@ -93,7 +100,7 @@ def verifier_username(brut): raise UsernameInvalide("Trop long : %d caractères maximum." % USERNAME_MAX) mauvais = [] for c in u: - if not (c.isalnum() or c in SPECIAUX) and c not in mauvais: + if not (_latin_ou_chiffre(c) or c in SPECIAUX) and c not in mauvais: mauvais.append(c) if mauvais: raise UsernameInvalide("Caractère non accepté : « %s ». Lettres, chiffres et . @ - _ ! ? ¿ seulement."