Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(webhook): skip URL re-validation when an update keeps the URL

Yudhi Armyndharis03f6c95d76bb
diff --git a/src/modules/webhook/webhook.service.spec.ts b/src/modules/webhook/webhook.service.spec.ts
index 1373b0cec..d77be1d81 100644
--- a/src/modules/webhook/webhook.service.spec.ts
+++ b/src/modules/webhook/webhook.service.spec.ts
@@ -395,6 +395,40 @@ describe('WebhookService', () => {
expect(webhook.url).toBe('https://example.com/webhook');
expect(repository.save).not.toHaveBeenCalled();
});
+
+ describe('with the SSRF guard on', () => {
+ const origProtect = process.env.WEBHOOK_SSRF_PROTECT;
+ beforeEach(() => delete process.env.WEBHOOK_SSRF_PROTECT); // default: on
+ afterEach(() => {
+ if (origProtect === undefined) delete process.env.WEBHOOK_SSRF_PROTECT;
+ else process.env.WEBHOOK_SSRF_PROTECT = origProtect;
+ });
+
+ it('saves an edit that re-sends an unchanged URL the guard would now refuse', async () => {
+ const webhook = createMockWebhook({ url: 'https://169.254.169.254/hook' });
+ (repository.findOne as jest.Mock).mockResolvedValue(webhook);
+ (repository.save as jest.Mock).mockImplementation(w => Promise.resolve(w));
+
+ const result = await service.update('sess-1', 'wh-uuid-1', {
+ url: 'https://169.254.169.254/hook',
+ active: false,
+ });
+
+ expect(result.active).toBe(false);
+ expect(repository.save).toHaveBeenCalledWith(expect.objectContaining({ active: false }));
+ });
+
+ it('still refuses a changed URL the guard blocks', async () => {
+ const webhook = createMockWebhook();
+ (repository.findOne as jest.Mock).mockResolvedValue(webhook);
+
+ await expect(
+ service.update('sess-1', 'wh-uuid-1', { url: 'https://169.254.169.254/hook', active: false }),
+ ).rejects.toMatchObject({ status: 400 });
+ expect(webhook.url).toBe('https://example.com/webhook');
+ expect(repository.save).not.toHaveBeenCalled();
+ });
+ });
});
// ── delete ────────────────────────────────────────────────────────
diff --git a/src/modules/webhook/webhook.service.ts b/src/modules/webhook/webhook.service.ts
index 8e470f2c8..9b0416402 100644
--- a/src/modules/webhook/webhook.service.ts
+++ b/src/modules/webhook/webhook.service.ts
@@ -221,7 +221,10 @@ export class WebhookService implements OnModuleInit, OnModuleDestroy {
async update(sessionId: string, id: string, dto: UpdateWebhookDto): Promise<Webhook> {
const webhook = await this.findOne(sessionId, id);
- if (dto.url !== undefined) {
+ // An unchanged URL is not re-validated: every edit re-sends it, so a webhook whose host stopped
+ // resolving or became SSRF-blocked could not otherwise be deactivated or re-filtered. Delivery
+ // still checks the URL on every send.
+ if (dto.url !== undefined && dto.url !== webhook.url) {
await this.validateWebhookUrl(dto.url);
webhook.url = dto.url;
}