mirror of
https://github.com/formbricks/formbricks.git
synced 2025-12-22 22:20:52 -06:00
Compare commits
1 Commits
fix/block-
...
mattinannt
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
623e82ff4d |
@@ -1,10 +1,13 @@
|
||||
import { prisma } from "@formbricks/database";
|
||||
import { sendForgotPasswordEmail } from "@formbricks/email";
|
||||
import { loginLimiter } from "@/app/middleware/bucket";
|
||||
|
||||
export const POST = async (request: Request) => {
|
||||
const { email } = await request.json();
|
||||
|
||||
try {
|
||||
await loginLimiter(request.headers.get("x-forwarded-for") || request.connection.remoteAddress);
|
||||
|
||||
const foundUser = await prisma.user.findUnique({
|
||||
where: {
|
||||
email: email.toLowerCase(),
|
||||
|
||||
@@ -29,3 +29,8 @@ export const syncUserIdentificationLimiter = rateLimit({
|
||||
interval: SYNC_USER_IDENTIFICATION_RATE_LIMIT.interval,
|
||||
allowedPerInterval: SYNC_USER_IDENTIFICATION_RATE_LIMIT.allowedPerInterval,
|
||||
});
|
||||
|
||||
export const forgotPasswordLimiter = rateLimit({
|
||||
interval: LOGIN_RATE_LIMIT.interval,
|
||||
allowedPerInterval: LOGIN_RATE_LIMIT.allowedPerInterval,
|
||||
});
|
||||
|
||||
@@ -28,3 +28,5 @@ export const isSyncWithUserIdentificationEndpoint = (
|
||||
const match = url.match(regex);
|
||||
return match ? { environmentId: match[1], userId: match[2] } : false;
|
||||
};
|
||||
|
||||
export const forgotPasswordRoute = (url: string) => url === "/api/v1/users/forgot-password";
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
shareUrlLimiter,
|
||||
signUpLimiter,
|
||||
syncUserIdentificationLimiter,
|
||||
forgotPasswordLimiter,
|
||||
} from "@/app/middleware/bucket";
|
||||
import {
|
||||
clientSideApiRoute,
|
||||
@@ -12,6 +13,7 @@ import {
|
||||
loginRoute,
|
||||
shareUrlRoute,
|
||||
signupRoute,
|
||||
forgotPasswordRoute,
|
||||
} from "@/app/middleware/endpointValidator";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { NextResponse } from "next/server";
|
||||
@@ -60,6 +62,8 @@ export const middleware = async (request: NextRequest) => {
|
||||
}
|
||||
} else if (shareUrlRoute(request.nextUrl.pathname)) {
|
||||
await shareUrlLimiter(`share-${ip}`);
|
||||
} else if (forgotPasswordRoute(request.nextUrl.pathname)) {
|
||||
await forgotPasswordLimiter(`forgot-password-${ip}`);
|
||||
}
|
||||
return NextResponse.next();
|
||||
} catch (e) {
|
||||
@@ -83,5 +87,6 @@ export const config = {
|
||||
"/api/auth/signout",
|
||||
"/auth/login",
|
||||
"/api/packages/:path*",
|
||||
"/api/v1/users/forgot-password",
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user