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.

add rate limiting

Kiran Ke94896ce5956
diff --git a/apps/web/app/api/auth/reset-password/route.ts b/apps/web/app/api/auth/reset-password/route.ts
index 87620c15a4..dd17ff5f1f 100644
--- a/apps/web/app/api/auth/reset-password/route.ts
+++ b/apps/web/app/api/auth/reset-password/route.ts
@@ -1,5 +1,5 @@
import { DubApiError, handleAndReturnErrorResponse } from "@/lib/api/errors";
-import { parseRequestBody } from "@/lib/api/utils";
+import { parseRequestBody, ratelimitOrThrow } from "@/lib/api/utils";
import { hashPassword } from "@/lib/auth/password";
import { prisma } from "@/lib/prisma";
import { resetPasswordSchema } from "@/lib/zod/schemas/auth";
@@ -10,6 +10,8 @@ import { NextRequest, NextResponse } from "next/server";
// POST /api/auth/reset-password - reset password using the reset token
export async function POST(req: NextRequest) {
try {
+ await ratelimitOrThrow(req, "reset-password");
+
const { token, password } = resetPasswordSchema.parse(
await parseRequestBody(req),
);
diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.ts
index 54eddc2e34..fe2f6529c1 100644
--- a/apps/web/lib/auth/options.ts
+++ b/apps/web/lib/auth/options.ts
@@ -13,6 +13,7 @@ import EmailProvider from "next-auth/providers/email";
import GithubProvider from "next-auth/providers/github";
import GoogleProvider from "next-auth/providers/google";
import { cookies } from "next/headers";
+import { ratelimitOrThrow } from "../api/utils";
import { dub } from "../dub";
import { subscribe } from "../flodesk";
import { isStored, storage } from "../storage";
@@ -181,7 +182,7 @@ export const authOptions: NextAuthOptions = {
email: { type: "email" },
password: { type: "password" },
},
- async authorize(credentials) {
+ async authorize(credentials, req) {
if (!credentials) {
throw new Error("no-credentials");
}
@@ -192,6 +193,9 @@ export const authOptions: NextAuthOptions = {
throw new Error("no-credentials");
}
+ // @ts-ignore
+ await ratelimitOrThrow(req, "login-with-credentials");
+
const user = await prisma.user.findUnique({
where: { email },
select: {