Files
documenso/packages/trpc/server/webhook-router/schema.ts
T
Lucas Smith 6b1b1d0417 fix: improve webhook execution (#2608)
Webhook URLs were being fetched without validating whether they
resolved to private/loopback addresses, exposing the server to SSRF.

Current SSRF is best effort and fail open, you should never host
services that
you cant risk exposure of.

This extracts webhook execution into a shared module that validates
URLs against private IP ranges (including DNS resolution), enforces
timeouts, and disables redirect following. The resend route now
queues through the job system instead of calling fetch inline.
2026-03-13 15:02:09 +11:00

48 lines
1.4 KiB
TypeScript

import { WebhookTriggerEvents } from '@prisma/client';
import { z } from 'zod';
import { isPrivateUrl } from '@documenso/lib/server-only/webhooks/is-private-url';
export const ZWebhookUrlSchema = z
.string()
.url()
.refine((url) => !isPrivateUrl(url), {
message: 'Webhook URL cannot point to a private or loopback address',
});
export const ZCreateWebhookRequestSchema = z.object({
webhookUrl: ZWebhookUrlSchema,
eventTriggers: z
.array(z.nativeEnum(WebhookTriggerEvents))
.min(1, { message: 'At least one event trigger is required' }),
secret: z.string().nullable(),
enabled: z.boolean(),
});
export type TCreateWebhookFormSchema = z.infer<typeof ZCreateWebhookRequestSchema>;
export const ZGetWebhookByIdRequestSchema = z.object({
id: z.string(),
});
export type TGetWebhookByIdRequestSchema = z.infer<typeof ZGetWebhookByIdRequestSchema>;
export const ZEditWebhookRequestSchema = ZCreateWebhookRequestSchema.extend({
id: z.string(),
});
export type TEditWebhookRequestSchema = z.infer<typeof ZEditWebhookRequestSchema>;
export const ZDeleteWebhookRequestSchema = z.object({
id: z.string(),
});
export type TDeleteWebhookRequestSchema = z.infer<typeof ZDeleteWebhookRequestSchema>;
export const ZTriggerTestWebhookRequestSchema = z.object({
id: z.string(),
event: z.nativeEnum(WebhookTriggerEvents),
});
export type TTriggerTestWebhookRequestSchema = z.infer<typeof ZTriggerTestWebhookRequestSchema>;