mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
Admin Panel / Settings / Features gets one switch, stored as webhooksDisabled on the Settings document and saved by the site-admin method saveWebhooksDisabled (audited). While it is on: - nothing is sent: board and global webhooks, two-way webhooks, Mattermost direct messages, the grouped and scheduled queue, durable Sync webhooks, the login and registration webhook and bot dispatches all ask webhooksOff() first (models/lib/webhooksSwitch.js SENDERS); - adding or changing a webhook is refused: the Integrations deny rules, the REST POST/PUT and activities routes (403 webhooks-disabled), a webhook's own delivery settings and saveAccountWebhook. Each refusal is recorded in Admin Panel / Problems as "Webhooks turned off" (authz.webhooks-disabled, blocksAccount: false); a silent non-send is never recorded; - nothing is deleted, so turning it off brings every webhook back. Removing a webhook stays allowed. Also the site-admin method webhooksReportPage for the coming Admin Panel / Problems report: every integration with its board and owner, the token reduced to whether one is set, secrets masked in the URL. Tests: tests/webhooksSwitch.test.cjs (the queue sends nothing and keeps what waits; every webhookFetch caller is a sender that asks or is listed as not a webhook; every write path refuses and records; report rows carry no token), a server mocha test, and the existing vm-driven suites supplied with the switch, with a negative case that nothing is sent. Thanks to xet7 !
61 lines
2.5 KiB
JavaScript
61 lines
2.5 KiB
JavaScript
import { Meteor } from 'meteor/meteor';
|
|
import { Mongo } from 'meteor/mongo';
|
|
import Integrations from '/models/integrations';
|
|
import { ensureIndex } from '/server/lib/mongoStartup';
|
|
// Off Sandstorm exactly fetchSafe (server/lib/ssrfGuard.js); in a grain, through
|
|
// the Powerbox grant a board admin gave this webhook, when there is one.
|
|
import { webhookFetch } from '/server/sandstormEgress';
|
|
const { createWebhookOutbox } = require('/server/lib/webhookOutbox');
|
|
// Admin Panel / Settings / Features / Turn off all webhooks: nothing is queued
|
|
// or sent while it is on; waiting jobs are kept.
|
|
import { webhooksOff } from '/server/webhooksSwitch';
|
|
|
|
// #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,
|
|
webhooksOff,
|
|
// The same SSRF-guarded transport as an immediate webhook (IntegrationBleed).
|
|
post: async (url, request) => {
|
|
try {
|
|
return await webhookFetch(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);
|
|
});
|