mirror of
https://github.com/documenso/documenso.git
synced 2026-07-13 06:25:01 +10:00
6b1b1d0417
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.
48 lines
1.4 KiB
TypeScript
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>;
|