From 2d8a40e3b88894dcf1543de376271dfc9ae2d0a1 Mon Sep 17 00:00:00 2001 From: "borja (aider)" Date: Thu, 27 Mar 2025 17:19:54 +0100 Subject: [PATCH] fix: handle undefined webhook config and improve URL validation --- src/services/webhook-manager.ts | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/services/webhook-manager.ts b/src/services/webhook-manager.ts index b7e5d08..e97c500 100644 --- a/src/services/webhook-manager.ts +++ b/src/services/webhook-manager.ts @@ -37,14 +37,17 @@ export class WebhookManager { throw new Error(`Missing required environment variables: ${missing.join(', ')}`); } - if (!process.env.WEBHOOK_URL) { - throw new Error('WEBHOOK_URL environment variable is required'); + if (!process.env.WEBHOOK_URL?.trim()) { + throw new Error('WEBHOOK_URL environment variable is required and cannot be empty'); } try { - new URL(process.env.WEBHOOK_URL); - } catch { - throw new Error('WEBHOOK_URL must be a valid URL'); + const url = new URL(process.env.WEBHOOK_URL); + if (!['http:', 'https:'].includes(url.protocol)) { + throw new Error('WEBHOOK_URL must use http or https protocol'); + } + } catch (e) { + throw new Error(`Invalid WEBHOOK_URL: ${e.message}`); } } @@ -77,12 +80,16 @@ export class WebhookManager { const config = this.getConfig(); const apiUrl = this.getApiUrl(); + const logSafeUrl = (url: string) => url ? `${url.substring(0, 20)}...` : 'invalid-url'; + console.log('ℹ️ Attempting to register webhook:', { apiUrl, config: { ...config, - // Don't log full URL for security - url: `${config.url.substring(0, 20)}...` + webhook: { + ...config.webhook, + url: logSafeUrl(config.webhook.url) + } } });