diff --git a/backend/src/controllers/global-preferences/webhook-preferences.controller.ts b/backend/src/controllers/global-preferences/webhook-preferences.controller.ts index 5c768a1..ec5706a 100644 --- a/backend/src/controllers/global-preferences/webhook-preferences.controller.ts +++ b/backend/src/controllers/global-preferences/webhook-preferences.controller.ts @@ -13,11 +13,15 @@ export const updateWebhookPreferences = async (req: Request, res: Response) => { try { const globalPreferences = await globalPrefService.getGlobalPreferences(); - globalPreferences.webhooksPreferences.enabled = webhookPreferences.enabled; - if (webhookPreferences.url) { - globalPreferences.webhooksPreferences.url = webhookPreferences.url; - } + // TODO: Validate the URL if webhooks are enabled by making a test request + globalPreferences.webhooksPreferences = { + enabled: webhookPreferences.enabled, + url: + webhookPreferences.url === undefined + ? globalPreferences.webhooksPreferences.url + : webhookPreferences.url + }; await globalPrefService.saveGlobalPreferences(globalPreferences); diff --git a/backend/src/middlewares/request-validators/preferences-validator.middleware.ts b/backend/src/middlewares/request-validators/preferences-validator.middleware.ts index e853d3e..7665d18 100644 --- a/backend/src/middlewares/request-validators/preferences-validator.middleware.ts +++ b/backend/src/middlewares/request-validators/preferences-validator.middleware.ts @@ -15,7 +15,11 @@ import { rejectUnprocessableRequest } from '../../models/error.model.js'; const WebhookPreferencesSchema: z.ZodType = z .object({ enabled: z.boolean(), - url: z.string().url().optional() + url: z + .string() + .url('Must be a valid URL') + .regex(/^https?:\/\//, { message: 'URL must start with http:// or https://' }) + .optional() }) .refine( (data) => {