From 699ed4cb5375186ab07abc0b2c1582f2684e5a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 28 Oct 2026 20:15:31 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=20auth:=20email=20normalization=20?= =?UTF-8?q?touches=20ASCII=20only,=20so=20look-alikes=20cannot=20fold=20in?= =?UTF-8?q?to=20an=20address?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/im-core/src/names.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/im-core/src/names.rs b/crates/im-core/src/names.rs index 9149373..64ff074 100644 --- a/crates/im-core/src/names.rs +++ b/crates/im-core/src/names.rs @@ -27,9 +27,12 @@ pub const MAX_LOCAL_LEN: usize = 64; /// Longest domain label, in bytes (RFC 1035). const MAX_LABEL_LEN: usize = 63; -/// The stored form of an address: surrounding whitespace removed, then lowercased. +/// The stored form of an address: surrounding ASCII whitespace removed, then ASCII lowercased. +/// +/// Only ASCII is touched. Unicode trimming or case folding would turn look-alikes (a no-break space, +/// the Kelvin sign) into an existing address; left alone, they fail the ASCII shape check instead. pub fn normalize_email(input: &str) -> String { - input.trim().to_lowercase() + input.trim_ascii().to_ascii_lowercase() } /// Normalises `input` and checks its shape. Returns the stored form. @@ -155,6 +158,20 @@ mod tests { ); } + #[test] + fn look_alikes_do_not_fold_into_an_address() { + assert_ne!( + normalize_email("\u{a0}admin@example.test"), + "admin@example.test" + ); + assert_ne!( + normalize_email("\u{212a}elvin@example.test"), + "kelvin@example.test" + ); + assert!(parse_email("\u{a0}admin@example.test").is_err()); + assert!(parse_email("\u{212a}elvin@example.test").is_err()); + } + #[test] fn display_names_are_trimmed_and_checked() { assert_eq!(