forked from calcom/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add guest email blacklist (calcom#15255)
* chore: Add guest email blacklist * types * Added check to only log when we've removed one * feat: add verification logic * chore: use base exftract email * Added toLowerCase for guest email checks --------- Co-authored-by: Udit Takkar <[email protected]>
- Loading branch information
1 parent
4cf89d2
commit 3b1de34
Showing
8 changed files
with
88 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Function to extract base email | ||
export const extractBaseEmail = (email: string): string => { | ||
const [localPart, domain] = email.split("@"); | ||
const baseLocalPart = localPart.split("+")[0]; | ||
return `${baseLocalPart}@${domain}`; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
packages/trpc/server/routers/publicViewer/checkIfUserEmailVerificationRequired.handler.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { extractBaseEmail } from "@calcom/lib/extract-base-email"; | ||
import logger from "@calcom/lib/logger"; | ||
|
||
import type { TUserEmailVerificationRequiredSchema } from "./checkIfUserEmailVerificationRequired.schema"; | ||
|
||
const log = logger.getSubLogger({ prefix: ["checkIfUserEmailVerificationRequired"] }); | ||
|
||
export const userWithEmailHandler = async ({ input }: { input: TUserEmailVerificationRequiredSchema }) => { | ||
const { userSessionEmail, email } = input; | ||
const baseEmail = extractBaseEmail(email); | ||
|
||
const blacklistedGuestEmails = process.env.BLACKLISTED_GUEST_EMAILS | ||
? process.env.BLACKLISTED_GUEST_EMAILS.split(",") | ||
: []; | ||
|
||
const blacklistedEmail = blacklistedGuestEmails.find( | ||
(guestEmail: string) => guestEmail.toLowerCase() === baseEmail.toLowerCase() | ||
); | ||
|
||
if (!!blacklistedEmail && blacklistedEmail !== userSessionEmail) { | ||
log.warn(`blacklistedEmail: ${blacklistedEmail}`); | ||
return true; | ||
} | ||
return false; | ||
}; | ||
|
||
export default userWithEmailHandler; |
8 changes: 8 additions & 0 deletions
8
packages/trpc/server/routers/publicViewer/checkIfUserEmailVerificationRequired.schema.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { z } from "zod"; | ||
|
||
export const ZUserEmailVerificationRequiredSchema = z.object({ | ||
userSessionEmail: z.string().optional(), | ||
email: z.string(), | ||
}); | ||
|
||
export type TUserEmailVerificationRequiredSchema = z.infer<typeof ZUserEmailVerificationRequiredSchema>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters