Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(email): disallow single quote in email parser (#3960)
Will Hutchinsona458fe41b7c0
diff --git a/rust/cloud-storage/authentication_service/src/api/webhooks/user/create_user_webhook.rs b/rust/cloud-storage/authentication_service/src/api/webhooks/user/create_user_webhook.rsindex e1724211f3..dcfc94307f 100644--- a/rust/cloud-storage/authentication_service/src/api/webhooks/user/create_user_webhook.rs+++ b/rust/cloud-storage/authentication_service/src/api/webhooks/user/create_user_webhook.rs@@ -10,6 +10,7 @@ use rand::Rng;use crate::{api::context::ApiContext, rate_limit_config::RATE_LIMIT_CONFIG};use authentication_service::service::user::create_user::create_user;use fusionauth::error::FusionAuthClientError;+use macro_user_id::email::Email;use model::authentication::webhooks::FusionAuthUserWebhook;/// FusionAuth create user webhook@@ -93,6 +94,13 @@ async fn create_user_webhook(ctx: &ApiContext, req: FusionAuthUserWebhook) -> anlet username = req.event.user.username.unwrap_or(email.clone());let fusionauth_user_id = req.event.user.id;+ // FusionAuth's own email validation is more permissive than ours (e.g. it allows+ // single quotes). The user.create event is transactional (AbsoluteMajority), so+ // returning an error here aborts the FusionAuth user creation entirely.+ if let Err(e) = Email::parse_from_str(&email) {+ anyhow::bail!("email is not a valid macro email: {e}");+ }+// rate limit check for user creationlet rate_limit = ctx.macro_cache_clientdiff --git a/rust/cloud-storage/email_validator/src/lib.rs b/rust/cloud-storage/email_validator/src/lib.rsindex ae56763fb7..ec262291fd 100644--- a/rust/cloud-storage/email_validator/src/lib.rs+++ b/rust/cloud-storage/email_validator/src/lib.rs@@ -4,8 +4,10 @@ use lazy_static::lazy_static;use regex::Regex;lazy_static! {+ // Note: the single quote (') is RFC 5322 atext and thus valid in the local part,+ // but we deliberately reject it as a policy choice (matching macro_user_id) — do not add it back.static ref EMAIL_REGEX: Regex = Regex::new(- r"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$"+ r"^[a-zA-Z0-9.!#$%&*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$").unwrap();}@@ -58,6 +60,12 @@ mod tests {("test@\\test.com", false),("[email protected]", true),("[email protected]", true),+ // single quotes are not allowed+ ("o'[email protected]", false),+ ("'[email protected]", false),+ ("test'@test.com", false),+ ("test+ta'[email protected]", false),+ ("test@te'st.com", false),];for email in emails {diff --git a/rust/cloud-storage/macro_user_id/src/email.rs b/rust/cloud-storage/macro_user_id/src/email.rsindex a082cb35ce..b538a70c19 100644--- a/rust/cloud-storage/macro_user_id/src/email.rs+++ b/rust/cloud-storage/macro_user_id/src/email.rs@@ -34,8 +34,10 @@ fn domain(input: &str) -> IResult<&str, &str> {}// Parser for local part (before @)+// Note: the single quote (') is RFC 5322 atext and thus valid in the local part,+// but we deliberately reject it as a policy choice — do not add it back.fn atom(input: &str) -> IResult<&str, &str> {- take_while1(|c: char| c.is_ascii_alphanumeric() || "!#$%&'*+/=?^_`{|}~-".contains(c))+ take_while1(|c: char| c.is_ascii_alphanumeric() || "!#$%&*+/=?^_`{|}~-".contains(c)).parse(input)}diff --git a/rust/cloud-storage/macro_user_id/src/email/tests.rs b/rust/cloud-storage/macro_user_id/src/email/tests.rsindex d5729cd9e5..9d3038cb40 100644--- a/rust/cloud-storage/macro_user_id/src/email/tests.rs+++ b/rust/cloud-storage/macro_user_id/src/email/tests.rs@@ -26,6 +26,12 @@ fn it_should_fail() {"sean@@macro.com",r#"foo"@macro.com"@example.com"#,+ // single quotes are not allowed+ "sean'[email protected]",+ "'[email protected]",+ "sean'@macro.com",+ "sean+ta'[email protected]",+ "sean@mac'ro.com",];invalid_emails.iter()