mirror of
https://github.com/wekan/wekan.git
synced 2026-11-20 14:45:01 -05:00
A grain has no network but the bridge proxy, so an outgoing webhook now leaves only through an API a board admin approved in the Powerbox for that webhook's address: each saved webhook offers "Allow this grain to reach this address". The grant belongs to the destination, not to a person, is found by the URL being sent to, and is approved as the address's parent path so the bridge delivers to the exact address. Every sender - immediate, grouped and stored - goes through webhookFetch, which off Sandstorm, or for an address no grant covers, is exactly the SSRF-guarded fetchSafe. The REST API called with a Sandstorm API key acts as the key's user: in a grain the bridge sets X-Sandstorm-User-Id itself. Only in a grain, only after a WeKan token, only for an existing enabled account, and a key without participate reads only. New strings translated in all languages. Thanks to xet7 !
57 lines
2.3 KiB
JavaScript
57 lines
2.3 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');
|
|
|
|
// #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 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);
|
|
});
|