Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Update send-otp.ts

Steven Teyf20c674a414d
diff --git a/apps/web/lib/actions/send-otp.ts b/apps/web/lib/actions/send-otp.ts
index be8162470e..92dc490019 100644
--- a/apps/web/lib/actions/send-otp.ts
+++ b/apps/web/lib/actions/send-otp.ts
@@ -2,6 +2,7 @@
import { ratelimit, redis } from "@/lib/upstash";
import { prisma } from "@dub/prisma";
+import { get } from "@vercel/edge-config";
import { sendEmail } from "emails";
import VerifyEmail from "emails/verify-email";
import { flattenValidationErrors } from "next-safe-action";
@@ -33,22 +34,37 @@ export const sendOtpAction = actionClient
throw new Error("Too many requests. Please try again later.");
}
+ if (email.includes("+") && email.endsWith("@gmail.com")) {
+ throw new Error(
+ "Email addresses with + are not allowed. Please use your work email instead.",
+ );
+ }
+
const domain = email.split("@")[1];
- const isDisposable = await redis.sismember(
- "disposableEmailDomains",
- domain,
- );
+
+ const [isDisposable, emailDomainTerms] = await Promise.all([
+ redis.sismember("disposableEmailDomains", domain),
+ get("emailDomainTerms"),
+ ]);
if (isDisposable) {
throw new Error(
- "Disposable email addresses are not allowed. If you think this is a mistake, please contact us at [email protected]",
+ "Invalid email address – please use your work email instead. If you think this is a mistake, please contact us at [email protected]",
);
}
- if (email.includes("+") && email.endsWith("@gmail.com")) {
- throw new Error(
- "Email addresses with + are not allowed. Please use your work email instead.",
+ if (emailDomainTerms && Array.isArray(emailDomainTerms)) {
+ const blacklistedEmailDomainTermsRegex = new RegExp(
+ emailDomainTerms
+ .map((term: string) => term.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) // replace special characters with escape sequences
+ .join("|"),
);
+
+ if (blacklistedEmailDomainTermsRegex.test(domain)) {
+ throw new Error(
+ "Invalid email address – please use your work email instead. If you think this is a mistake, please contact us at [email protected]",
+ );
+ }
}
const code = generateOTP();