chore: system wide ratelimit per path (#25080)
* chore: Add system wide rate limiting * Handle and convert HttpError to 429 * Make algo 32-bit to prevent <ES2020 error + fix sms manager unit test * Change core to common to go from 10 requests per minute to 200 * Remove redundant function * Fix integration tests * Make sure we allow all legal POST routes * Allow tRPC post calls * Add matcher tests on middleware * Add matcher tests on middleware * Fix matcher to not use regex * Fix missing POST allow rule for /api/auth/callback/credentials * Missed the api/book/event endpoints * Add missing pages/api routes * Remove POST middleware for now, very risky * Remove tests for POST protection --------- Co-authored-by: Volnei Munhoz <[email protected]>
This commit is contained in:
1 parent
a3fc17bc75
commit
1d6959c4ac
11 files changed
+251
-160
No files matched your search
@@ -2,7 +2,7 @@ import type { NextRequest } from "next/server";
|
||||
import TwilioClient from "twilio";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import { checkSMSRateLimit } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import { checkSMSRateLimit } from "@calcom/lib/smsLockState";
|
||||
import { WEBAPP_URL } from "@calcom/lib/constants";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import { setTestSMS } from "@calcom/lib/testSMS";
|
||||
@@ -85,6 +85,7 @@ export const sendSMS = async ({
|
||||
}
|
||||
|
||||
if (isWhatsapp) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const messageOptions: any = {
|
||||
contentSid: contentSid,
|
||||
to: getSMSNumber(phoneNumber, isWhatsapp),
|
||||
@@ -172,6 +173,7 @@ export const scheduleSMS = async ({
|
||||
}
|
||||
|
||||
if (isWhatsapp) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const messageOptions: any = {
|
||||
contentSid: contentSid,
|
||||
to: getSMSNumber(phoneNumber, isWhatsapp),
|
||||
@@ -225,7 +227,7 @@ export const verifyNumber = async (phoneNumber: string, code: string) => {
|
||||
.services(process.env.TWILIO_VERIFY_SID)
|
||||
.verificationChecks.create({ to: phoneNumber, code: code });
|
||||
return verification_check.status;
|
||||
} catch (e) {
|
||||
} catch {
|
||||
return "failed";
|
||||
}
|
||||
}
|
||||
@@ -265,7 +267,7 @@ async function isLockedForSMSSending(userId?: number | null, teamId?: number | n
|
||||
(membership) => membership.team.smsLockState === SMSLockState.LOCKED
|
||||
);
|
||||
|
||||
if (!!memberOfLockedTeam) {
|
||||
if (memberOfLockedTeam) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import * as twilio from "@calcom/features/ee/workflows/lib/reminders/providers/t
|
||||
import type { Workflow, WorkflowStep } from "@calcom/features/ee/workflows/lib/types";
|
||||
import { getSubmitterEmail } from "@calcom/features/tasker/tasks/triggerFormSubmittedNoEvent/formSubmissionValidation";
|
||||
import { UserRepository } from "@calcom/features/users/repositories/UserRepository";
|
||||
import { checkSMSRateLimit } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import { checkSMSRateLimit } from "@calcom/lib/smsLockState";
|
||||
import { SENDER_NAME } from "@calcom/lib/constants";
|
||||
import { formatCalEventExtended } from "@calcom/lib/formatCalendarEvent";
|
||||
import { withReporting } from "@calcom/lib/sentryWrapper";
|
||||
|
||||
Reference in new issue
Block a user