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(', ')}`);
}
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)
}
}
});

Loading…
Cancel
Save