Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
Add email-based rate limiting to OTP requests
Cursor Agentd3ee5ff1313d
diff --git a/app/(ee)/api/workflow-entry/domains/[...domainSlug]/route.ts b/app/(ee)/api/workflow-entry/domains/[...domainSlug]/route.tsindex 444e26b1..685d3ad0 100644--- a/app/(ee)/api/workflow-entry/domains/[...domainSlug]/route.ts+++ b/app/(ee)/api/workflow-entry/domains/[...domainSlug]/route.ts@@ -125,7 +125,21 @@ async function handleVerify(req: NextRequest, link: any) {const { email } = validation.data;- // Rate limiting+ // Rate limit per email/link combination (1 per 30 seconds) to prevent OTP flooding+ const { success: emailLimitSuccess } = await ratelimit(1, "30 s").limit(+ `workflow-otp:${link.id}:${email}`,+ );+ if (!emailLimitSuccess) {+ return NextResponse.json(+ {+ error:+ "Please wait before requesting another code. Try again in 30 seconds.",+ },+ { status: 429 },+ );+ }++ // Additional IP-based rate limit (10 per minute) to prevent abuse across different emailsconst ipAddressValue = ipAddress(req);const { success } = await ratelimit(10, "1 m").limit(`workflow-otp:${ipAddressValue}`,diff --git a/app/(ee)/api/workflow-entry/link/[entryLinkId]/verify/route.ts b/app/(ee)/api/workflow-entry/link/[entryLinkId]/verify/route.tsindex 19dbfa0b..469e8a53 100644--- a/app/(ee)/api/workflow-entry/link/[entryLinkId]/verify/route.ts+++ b/app/(ee)/api/workflow-entry/link/[entryLinkId]/verify/route.ts@@ -76,7 +76,21 @@ export async function POST();}- // Rate limiting+ // Rate limit per email/entryLink combination (1 per 30 seconds) to prevent OTP flooding+ const { success: emailLimitSuccess } = await ratelimit(1, "30 s").limit(+ `workflow-otp:${entryLinkId}:${email}`,+ );+ if (!emailLimitSuccess) {+ return NextResponse.json(+ {+ error:+ "Please wait before requesting another code. Try again in 30 seconds.",+ },+ { status: 429 },+ );+ }++ // Additional IP-based rate limit (10 per minute) to prevent abuse across different emailsconst ipAddressValue = ipAddress(req);const { success } = await ratelimit(10, "1 m").limit(`workflow-otp:${ipAddressValue}`,diff --git a/app/api/views-dataroom/route.ts b/app/api/views-dataroom/route.tsindex 0d73e496..71cf464a 100644--- a/app/api/views-dataroom/route.ts+++ b/app/api/views-dataroom/route.ts@@ -400,6 +400,21 @@ export async function POST(request: NextRequest) {if (link.emailAuthenticated && !code && !token && !dataroomVerified) {const ipAddressValue = ipAddress(request);+ // Rate limit per email/link combination (1 per 30 seconds) to prevent OTP flooding+ const { success: emailLimitSuccess } = await ratelimit(1, "30 s").limit(+ `send-otp:${linkId}:${email}`,+ );+ if (!emailLimitSuccess) {+ return NextResponse.json(+ {+ message:+ "Please wait before requesting another code. Try again in 30 seconds.",+ },+ { status: 429 },+ );+ }++ // Additional IP-based rate limit (10 per minute) to prevent abuse across different emailsconst { success } = await ratelimit(10, "1 m").limit(`send-otp:${ipAddressValue}`,);diff --git a/app/api/views/route.ts b/app/api/views/route.tsindex 4aeb469c..80ad1a95 100644--- a/app/api/views/route.ts+++ b/app/api/views/route.ts@@ -288,6 +288,21 @@ export async function POST(request: NextRequest) {if (link.emailAuthenticated && !code && !token) {const ipAddressValue = ipAddress(request);+ // Rate limit per email/link combination (1 per 30 seconds) to prevent OTP flooding+ const { success: emailLimitSuccess } = await ratelimit(1, "30 s").limit(+ `send-otp:${linkId}:${email}`,+ );+ if (!emailLimitSuccess) {+ return NextResponse.json(+ {+ message:+ "Please wait before requesting another code. Try again in 30 seconds.",+ },+ { status: 429 },+ );+ }++ // Additional IP-based rate limit (10 per minute) to prevent abuse across different emailsconst { success } = await ratelimit(10, "1 m").limit(`send-otp:${ipAddressValue}`,);