Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

fix(2FA): return `429` when too many failed attemps

Rudy B.fc32e39ac0de
diff --git a/src/app/api/2fa/disable/route.ts b/src/app/api/2fa/disable/route.ts
index 667cc3ceb..859deac6d 100644
--- a/src/app/api/2fa/disable/route.ts
+++ b/src/app/api/2fa/disable/route.ts
@@ -73,11 +73,16 @@ export async function POST(request: Request) {
// Verify rate limit
const rateCheck = await checkRateLimit(userId);
if (!rateCheck.allowed) {
- return badRequest({
- code: 'two-factor-error-too-many-attempts',
- message: 'Too many failed attempts',
- lockedUntil: rateCheck.lockedUntil,
- });
+ return Response.json(
+ {
+ error: {
+ code: 'two-factor-error-too-many-attempts',
+ message: 'Too many failed attempts',
+ lockedUntil: rateCheck.lockedUntil,
+ },
+ },
+ { status: 429 },
+ );
}
// Prevent OTP replay
diff --git a/src/app/api/2fa/setup/confirm/route.ts b/src/app/api/2fa/setup/confirm/route.ts
index 629a15c86..e64e558c3 100644
--- a/src/app/api/2fa/setup/confirm/route.ts
+++ b/src/app/api/2fa/setup/confirm/route.ts
@@ -33,11 +33,16 @@ export async function POST(request: Request) {
// Verify rate limit
const rateCheck = await checkRateLimit(userId);
if (!rateCheck.allowed) {
- return badRequest({
- code: 'two-factor-error-too-many-attempts',
- message: 'Too many failed attempts',
- lockedUntil: rateCheck.lockedUntil,
- });
+ return Response.json(
+ {
+ error: {
+ code: 'two-factor-error-too-many-attempts',
+ message: 'Too many failed attempts',
+ lockedUntil: rateCheck.lockedUntil,
+ },
+ },
+ { status: 429 },
+ );
}
// Prevent OTP replay