mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
The activity hook delivered webhooks through Meteor.call('outgoingWebhooks'),
and that method trusted a call without this.connection as the server's own.
Meteor gives a server-side Meteor.call the userId AND connection of the method
it runs in (ddp-server applyAsync), and a card moved from a browser runs in
that browser's method. So the server's own act-moveCard delivery arrived as a
client forging one: it was recorded as ssrf.webhook-forge (high) with the
mover's userId, and blockOnSecurityEvent set loginDisabled.
- deliverActivityWebhook() in server/notifications/outgoing.js is the server's
delivery: a function, not a method, so no client reaches it and no inherited
context changes it. It reads the integration again (enabled) and names the
activity's actor. server/models/activities.js calls it through safeDeliver.
- The outgoingWebhooks method treats every call as a client's: only the
card-opened notification, rebuilt from the card, as before for clients.
- Server deliveries no longer need the actor to be a member of the hook's
board, which also skipped a global webhook ('_global' is no board) and an
activity with no method behind it (REST, timers).
- securityLog.record() now passes the catalog key and blocksAccount to the
block decision. The stored row carries neither, so every 'high' blocked row
disabled whoever it named: a hook refused for its own internal address
disabled the mover too, and ssrf.redirect/ssrf.attachment's
blocksAccount: false never applied. ssrf.webhook is now blocksAccount:
false - the person whose move sent it did not write the hook's URL.
tests/hookBleedServerDelivery.test.cjs: the move delivered with nothing
logged, in an inherited context too; a forged call still refused, logged and
blocking; the card-opened notification; failing and internal hooks blocking
nobody, through record() itself; and a whole-tree scan that no server code
calls a this.connection-gated method from inside a client's method without
clearing the invocation. tests/playwright/specs/hook-bleed.e2e.js moves a
card through the Move dialog with a webhook enabled.
Thanks to do4me and xet7 !
Fixes #6782.
67 lines
2.2 KiB
JavaScript
67 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
// Regression coverage for #3575 / #1402. A slow or failing outgoing webhook
|
|
// must never delay the database mutation that emitted its activity.
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const vm = require('vm');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const read = relative => fs.readFileSync(path.join(root, relative), 'utf8');
|
|
const activities = read('server/models/activities.js');
|
|
const guardSource = read('server/lib/webhookGuard.js');
|
|
|
|
const sandbox = {
|
|
module: { exports: {} },
|
|
console: { error() {} },
|
|
TypeError,
|
|
};
|
|
vm.runInNewContext(
|
|
`${guardSource.replace('export async function safeDeliver', 'async function safeDeliver')}\n` +
|
|
'module.exports = { safeDeliver };',
|
|
sandbox,
|
|
);
|
|
const { safeDeliver } = sandbox.module.exports;
|
|
|
|
async function run() {
|
|
const deliveryBlock = activities.slice(
|
|
activities.indexOf(' if (integrations.length > 0)'),
|
|
activities.indexOf('\n});', activities.indexOf(' if (integrations.length > 0)')),
|
|
);
|
|
assert.match(deliveryBlock, /safeDeliver\(/);
|
|
assert.doesNotMatch(deliveryBlock, /await\s+safeDeliver\(/,
|
|
'activity insertion must not await webhook delivery');
|
|
// #6782: delivered by a function, never through the outgoingWebhooks method.
|
|
assert.match(deliveryBlock, /safeDeliver\(\(\) => deliverActivityWebhook\(integration, delivered, deliveredParams, userId \|\| doc\.userId\)\)/);
|
|
assert.doesNotMatch(deliveryBlock.replace(/\/\/.*$/gm, ''), /Meteor\.call/);
|
|
|
|
let release;
|
|
const hanging = safeDeliver(() => new Promise(resolve => {
|
|
release = resolve;
|
|
}));
|
|
const callerContinued = await Promise.race([
|
|
Promise.resolve('continued'),
|
|
hanging.then(() => 'blocked'),
|
|
]);
|
|
assert.strictEqual(callerContinued, 'continued',
|
|
'starting a hanging delivery must return control to the caller');
|
|
release();
|
|
assert.strictEqual((await hanging).ok, true);
|
|
|
|
const failure = new Error('receiver closed connection');
|
|
const failed = await safeDeliver(async () => {
|
|
throw failure;
|
|
});
|
|
assert.strictEqual(failed.ok, false);
|
|
assert.strictEqual(failed.error, failure);
|
|
|
|
console.log('webhookNonBlockingActivity: 3 tests passed');
|
|
}
|
|
|
|
run().catch(error => {
|
|
console.error(error);
|
|
process.exitCode = 1;
|
|
});
|