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
test: reject email sql injection vectors (#4074)
Sean Aye773da47ee4de
diff --git a/rust/cloud-storage/macro_user_id/src/email.rs b/rust/cloud-storage/macro_user_id/src/email.rsindex a082cb35ce..5626f23587 100644--- a/rust/cloud-storage/macro_user_id/src/email.rs+++ b/rust/cloud-storage/macro_user_id/src/email.rs@@ -18,12 +18,12 @@ use serde::{Deserialize, Serialize};#[cfg(test)]mod tests;-// Parser for domain labels+/// Parser for domain labelsfn domain_label(input: &str) -> IResult<&str, &str> {take_while1(|c: char| c.is_ascii_alphanumeric() || c == '-').parse(input)}-// Parser for the domain part+/// Parser for the domain partfn domain(input: &str) -> IResult<&str, &str> {recognize(verify(separated_list1(char('.'), domain_label),@@ -33,7 +33,7 @@ fn domain(input: &str) -> IResult<&str, &str> {.parse(input)}-// Parser for local part (before @)+/// Parser for local part (before @)fn atom(input: &str) -> IResult<&str, &str> {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..08b32477c6 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,9 @@ fn it_should_fail() {"sean@@macro.com",r#"foo"@macro.com"@example.com"#,+ // cannot have single quote in domain part+ "sean@mac'ro.com",+ "se'an@mac'ro.com",];invalid_emails.iter()@@ -36,6 +39,34 @@ fn it_should_fail() {});}+#[test]+fn known_sql_injection_payloads_are_not_valid_email_addresses() {+ let sql_injection_vectors = [+ "sean' OR '1'='[email protected]",+ "sean' UNION SELECT password FROM [email protected]",+ "[email protected]'; DROP TABLE users; --",+ "[email protected]' OR '1'='1",+ "sean'@macro.com OR 1=1",+ "sean'\nOR '1'='[email protected]",+ ];++ for input in sql_injection_vectors {+ assert!(+ Email::parse_from_str(input).is_err(),+ "parsed Email must not be constructible from SQL injection vector: {input}"+ );+ }+}++#[test]+fn local_part_may_contain_single_quote_without_being_sql_injection() {+ let email = Email::parse_from_str("o'[email protected]").unwrap();++ assert_eq!(email.email_str(), "o'[email protected]");+ assert_eq!(email.local_part(), "o'connor");+ assert_eq!(email.domain_part(), "macro.com");+}+#[test]fn local_part_works() {let email = Email::parse_from_str("###hello###[email protected]").unwrap();