Files
wekan/tests/globalWebhookEditCardActivity.test.cjs
T
Lauri Ojansivu b01c233269 Moving a card with an outgoing webhook no longer counts as HookBleed or disables the mover's account.
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.
2026-10-18 14:28:19 +03:00

86 lines
3.7 KiB
JavaScript

'use strict';
// Plain-Node source-pattern regression test (no Meteor) for #4912 ("Global
// Webhook act-editCard?" — a request to make the global webhook fire when a
// card is edited, e.g. title/description/due-date changes).
//
// This is already implemented: server/models/cards.js logs an Activities
// entry for title (`a-changedTitle`, #3619), description (`a-changedDescription`,
// #5482) and the timing fields (`a-${dueAt|startAt|endAt|receivedAt}`) whenever
// they change, and server/models/activities.js's Activities.after.insert hook
// turns every such activityType into `act-${activityType}` and dispatches it to
// any enabled integration whose boardId is the card's own board OR the special
// Integrations.Const.GLOBAL_WEBHOOK_ID, filtered by `activities: { $in: [description, 'all'] }`.
// So editing a card's title/description/due date already reaches a globally
// configured webhook today, under those activity names.
//
// Since 2026-10-02 (maintainer decision) a webhook may also opt into ONE
// consolidated `act-editCard` event (models/lib/editCardWebhook.js), so the
// selection and the per-webhook event name below go through that helper; the
// helper's own behaviour is pinned by tests/editCardWebhook.test.cjs.
//
// Run: node tests/globalWebhookEditCardActivity.test.cjs
const assert = require('assert');
const fs = require('fs');
const path = require('path');
const cardsSrc = fs.readFileSync(
path.join(__dirname, '..', 'server', 'models', 'cards.js'),
'utf8',
);
const activitiesSrc = fs.readFileSync(
path.join(__dirname, '..', 'server', 'models', 'activities.js'),
'utf8',
);
let passed = 0;
function test(name, fn) {
fn();
passed += 1;
console.log(' ok -', name);
}
// --- POSITIVE: cards.js logs an activity for each edit that #4912 asked about --
test('#4912: title changes log activityType a-changedTitle', () => {
assert.match(cardsSrc, /activityType:\s*'a-changedTitle'/);
});
test('#4912: description changes log activityType a-changedDescription', () => {
assert.match(cardsSrc, /activityType:\s*'a-changedDescription'/);
});
test('#4912: due/start/end/received date changes log activityType a-${action}', () => {
assert.match(cardsSrc, /const timingaction = \[\s*'receivedAt',\s*'dueAt',\s*'startAt',\s*'endAt',?\s*\];/);
assert.match(cardsSrc, /const activityType = `a-\$\{action\}`;/);
});
// --- POSITIVE: activities.js dispatches every logged activity to the global
// webhook (not just per-board integrations) ---------------------------------
test('#4912: outgoing-webhook dispatch is keyed off act-${activityType}, covering every activityType above', () => {
assert.match(activitiesSrc, /const description = `act-\$\{activity\.activityType\}`;/);
});
test('#4912: integrations are looked up on the card\'s board AND the global webhook id', () => {
assert.match(
activitiesSrc,
/const integrationBoardIds = board\s*\?\s*\[board\._id, Integrations\.Const\.GLOBAL_WEBHOOK_ID\]\s*:\s*\[Integrations\.Const\.GLOBAL_WEBHOOK_ID\];/,
);
});
test('#4912: integrations are filtered by this description, "all" or the act-editCard opt-in', () => {
assert.match(activitiesSrc, /activities:\s*\{\s*\$in:\s*webhookActivitySelection\(description\)\s*\}/);
const { webhookActivitySelection } = require('../models/lib/editCardWebhook');
assert.deepEqual(webhookActivitySelection('act-a-dueAt'), ['act-a-dueAt', 'all']);
});
test('#4912: matching integrations are delivered with their own event', () => {
assert.match(activitiesSrc, /const delivered = webhookDescriptionFor\(integration, description\);/);
// #6782: through deliverActivityWebhook, not the outgoingWebhooks method.
assert.match(activitiesSrc, /deliverActivityWebhook\(integration, delivered, deliveredParams,/);
});
console.log('\n' + passed + ' passed');