fix: add URL validation to webhook endpoints (#26593)

Validates webhook URLs on create and update:
- HTTPS required (HTTP allowed for self-hosted and E2E)
- Blocks private IP ranges and localhost
- Blocks cloud metadata endpoints

Existing webhooks are preserved: validation only applies when URL is created or changed.

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
Pedro CastroandDevin AI authored and GitHub committed 2026-02-05 16:18:10 -03:00
1 parent c57b517555
commit cb36fc201f
17 files changed
+386 -75

No files matched your search

@@ -2,6 +2,7 @@ import { v4 } from "uuid";
import { PermissionCheckService } from "@calcom/features/pbac/services/permission-check.service";
import { updateTriggerForExistingBookings } from "@calcom/features/webhooks/lib/scheduleTrigger";
import { validateUrlForSSRFSync } from "@calcom/lib/ssrfProtection";
import { prisma } from "@calcom/prisma";
import type { Webhook } from "@calcom/prisma/client";
import type { Prisma } from "@calcom/prisma/client";
@@ -23,6 +24,15 @@ type CreateOptions = {
export const createHandler = async ({ ctx, input }: CreateOptions) => {
const { user } = ctx;
// SSRF validation for webhook URL
const validation = validateUrlForSSRFSync(input.subscriberUrl);
if (!validation.isValid) {
throw new TRPCError({
code: "BAD_REQUEST",
message: `Webhook URL is not allowed: ${validation.error}`,
});
}
const webhookData: Prisma.WebhookCreateInput = {
id: v4(),
...input,
@@ -4,6 +4,7 @@ import {
deleteWebhookScheduledTriggers,
cancelNoShowTasksForBooking,
} from "@calcom/features/webhooks/lib/scheduleTrigger";
import { validateUrlForSSRFSync } from "@calcom/lib/ssrfProtection";
import { prisma } from "@calcom/prisma";
import { MembershipRole } from "@calcom/prisma/enums";
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
@@ -32,6 +33,17 @@ export const editHandler = async ({ input, ctx }: EditOptions) => {
return null;
}
// SSRF validation: only validate if URL is being changed
if (data.subscriberUrl && data.subscriberUrl !== webhook.subscriberUrl) {
const validation = validateUrlForSSRFSync(data.subscriberUrl);
if (!validation.isValid) {
throw new TRPCError({
code: "BAD_REQUEST",
message: `Webhook URL is not allowed: ${validation.error}`,
});
}
}
if (webhook.platform) {
const { user } = ctx;
if (user?.role !== "ADMIN") {
@@ -1,7 +1,7 @@
import { DEFAULT_WEBHOOK_VERSION } from "@calcom/features/webhooks/lib/interface/IWebhookRepository";
import type { EventPayloadType } from "@calcom/features/webhooks/lib/sendPayload";
import sendPayload from "@calcom/features/webhooks/lib/sendPayload";
import { validateUrlForSSRFSync } from "@calcom/lib/ssrfProtection";
import { getTranslation } from "@calcom/lib/server/i18n";
import type { TTestTriggerInputSchema } from "./testTrigger.schema";
@@ -13,6 +13,17 @@ type TestTriggerOptions = {
export const testTriggerHandler = async ({ ctx: _ctx, input }: TestTriggerOptions) => {
const { url, type, payloadTemplate = null, secret = null } = input;
// SSRF validation for webhook URL
const validation = validateUrlForSSRFSync(url);
if (!validation.isValid) {
return {
ok: false,
status: 400,
message: `Webhook URL is not allowed: ${validation.error}`,
};
}
const translation = await getTranslation("en", "common");
const language = {
locale: "en",