Skip to content

Commit bbe46ea

Browse files
Restrict the length of emails as per RFC (calcom#24269)
1 parent 7799b19 commit bbe46ea

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

packages/lib/emailSchema.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,15 @@ import { z } from "zod";
44
export const emailRegex =
55
/^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.']*)[A-Z0-9_+'-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
66

7-
export const emailSchema = z.string().regex(emailRegex);
7+
/**
8+
* RFC 5321 Section 4.5.3.1.3 specifies:
9+
* - Maximum email address length: 254 characters
10+
* - Local part (before @): max 64 characters
11+
* - Domain part (after @): max 253 characters
12+
*/
13+
const MAX_EMAIL_LENGTH = 254;
14+
15+
export const emailSchema = z
16+
.string()
17+
.max(MAX_EMAIL_LENGTH, { message: "Email address is too long" })
18+
.regex(emailRegex);

packages/prisma/zod-utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ export const emailSchema = emailRegexSchema;
709709
// I introduced this refinement(to be used with z.email()) as a short term solution until we upgrade to a zod
710710
// version that will include updates in the above PR.
711711
export const emailSchemaRefinement = (value: string) => {
712-
return emailRegex.test(value);
712+
return emailSchema.safeParse(value).success;
713713
};
714714

715715
export const signupSchema = z.object({

0 commit comments

Comments
 (0)