Files
wekan/server/notifications/webhookQueue.js
T
Lauri Ojansivu ab785acd1e Choose what notifications contain, and group and schedule them, for e-mail, the tray and webhooks.
One delivery model (models/lib/notificationDelivery.js) for every channel -
e-mail, the notification tray and outgoing webhooks - set in the
Notifications popup at Admin Panel, board and Member Settings scope, and in
each one-way webhook's form:

- Content. Webhooks: the text on or off, and which property groups are sent
  (standard, ids, names, links, actor, people, details), with checklist,
  list, swimlane and board names, before/after values, the card description
  and links added as opt-in groups. E-mail and tray: the classic sentence or
  a clear layout - the board as a link first, the actor and card in bold -
  and which parts are shown.
- Grouping: one message per event, per card, per board, or all together.
- Scheduling: immediately, every 5 minutes to 24 hours, or once a day, with
  optional quiet hours, in the time zone of whoever set it.

The most specific explicit setting wins: member, then board, then Admin
Panel for e-mail and tray; the webhook, then its board, then Admin Panel for
webhooks. A member can only leave their own name out of outgoing webhooks.
The built-in defaults keep today's behaviour. Grouped and scheduled webhooks
and e-mail go through durable queues that survive restarts; queued webhooks
use the SSRF guard and log a blocked address in Admin Panel - Problems.
Values of admin-only custom fields now reach only board admins in e-mail and
tray, and never a webhook.

The new strings are in English in every locale, pending Transifex.

Thanks to HaKePlan, Meeques and xet7 !

Fixes #3695,
Fixes #5171.
2026-10-10 15:28:26 +03:00

55 lines
2.1 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import Integrations from '/models/integrations';
import { ensureIndex } from '/server/lib/mongoStartup';
import { fetchSafe } from '/server/lib/ssrfGuard';
const { createWebhookOutbox } = require('/server/lib/webhookOutbox');
// #3695: grouped and scheduled outgoing webhooks (server/lib/webhookOutbox.js).
// Queued bodies are server-private: no client can read or write them.
export const WebhookJobs = new Mongo.Collection('notificationWebhookJobs');
export const WebhookLeases = new Mongo.Collection('notificationWebhookLeases');
for (const collection of [WebhookJobs, WebhookLeases]) {
collection.deny({ insert: () => true, update: () => true, remove: () => true });
}
export const webhookOutbox = createWebhookOutbox({
jobs: WebhookJobs.rawCollection(),
leases: WebhookLeases.rawCollection(),
getIntegration: id => Integrations.findOneAsync(id),
oneWayType: Integrations.Const.ONEWAY,
// The same SSRF-guarded transport as an immediate webhook (IntegrationBleed).
post: async (url, request) => {
try {
return await fetchSafe(url, { ...request, totalTimeoutMs: 30000 });
} catch (err) {
if (/^SSRF_GUARD:/.test(err && err.message)) {
// IntegrationBleed: a webhook pointed at an internal address.
try {
require('/server/lib/securityLog').record({
key: 'ssrf.webhook', action: 'blocked', source: 'webhookQueue',
detail: String(err.message).slice(0, 160),
});
} catch (e) { /* logging must never break the guard */ }
}
throw err;
}
},
});
Meteor.startup(async () => {
await ensureIndex(WebhookJobs, { state: 1, nextAttemptAt: 1, integrationId: 1 });
await ensureIndex(WebhookJobs, { integrationId: 1, state: 1, nextAttemptAt: 1 });
// Polling finds both new jobs and jobs left by a restart.
async function scan() {
try {
await webhookOutbox.drain();
} catch (error) {
console.error('Webhook queue scan failed; queued webhooks will be retried');
} finally {
Meteor.setTimeout(scan, 5000);
}
}
Meteor.setTimeout(scan, 5000);
});