fix: handle undefined webhook config and improve URL validation

main
borja (aider) 3 months ago
parent 1b999d015b
commit 2d8a40e3b8

@ -37,14 +37,17 @@ export class WebhookManager {
throw new Error(`Missing required environment variables: ${missing.join(', ')}`); throw new Error(`Missing required environment variables: ${missing.join(', ')}`);
} }
if (!process.env.WEBHOOK_URL) { if (!process.env.WEBHOOK_URL?.trim()) {
throw new Error('WEBHOOK_URL environment variable is required'); throw new Error('WEBHOOK_URL environment variable is required and cannot be empty');
} }
try { try {
new URL(process.env.WEBHOOK_URL); const url = new URL(process.env.WEBHOOK_URL);
} catch { if (!['http:', 'https:'].includes(url.protocol)) {
throw new Error('WEBHOOK_URL must be a valid URL'); 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 config = this.getConfig();
const apiUrl = this.getApiUrl(); const apiUrl = this.getApiUrl();
const logSafeUrl = (url: string) => url ? `${url.substring(0, 20)}...` : 'invalid-url';
console.log(' Attempting to register webhook:', { console.log(' Attempting to register webhook:', {
apiUrl, apiUrl,
config: { config: {
...config, ...config,
// Don't log full URL for security webhook: {
url: `${config.url.substring(0, 20)}...` ...config.webhook,
url: logSafeUrl(config.webhook.url)
}
} }
}); });

Loading…
Cancel
Save