mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 20:45:00 -05:00
A rule that moved a card to another board and then sent an email sent nothing: the email source check refused a card that had left the activity's board, in both engines. As decided, the email now reads the card on the destination board, but only when this run of the rule made the move, the destination opted into Sync effects, and the card is still there. The ordinary engine remembers its run's own move (RulesHelper.emailActivity), durable Sync proves it from a saved move of the same plan (ruleEmailActivity, ruleCardNow) and rechecks it before sending. The stored source binding (version 6) records the board the card left. Any other card off the board is refused as before, and an email may now follow a move to another board in a durable plan. Tests: binding positive and negative cases, a shape guard that nothing else can claim a followed move, and a server test of both engines that sends once from the destination and refuses a card nobody's run moved, a move to another board, and a destination that opted out. Thanks to xet7 !
95 lines
3.8 KiB
JavaScript
95 lines
3.8 KiB
JavaScript
'use strict';
|
|
|
|
// RuleBleed / GHSA-9w4x-hf2r-hc9v: automation actions run server-side and do
|
|
// not invoke Mongo collection allow/deny callbacks. Pin authorization at both
|
|
// rule registration and execution, including legacy actions already in data.
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const root = path.resolve(__dirname, '..');
|
|
const read = rel => fs.readFileSync(path.join(root, rel), 'utf8');
|
|
const button = read('server/rulesButton.js');
|
|
const helper = read('server/rulesHelper.js');
|
|
const rest = read('server/models/rules.js');
|
|
const playwrightDb = read('tests/playwright/helpers/db.js');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) {
|
|
fn();
|
|
passed += 1;
|
|
console.log(' ok -', name);
|
|
}
|
|
|
|
test('rule creation checks a different destination before inserting any document', () => {
|
|
const guard = button.indexOf('if (actionDoc.boardId !== boardId)');
|
|
const triggerInsert = button.indexOf('Triggers.insertAsync(', guard);
|
|
const insert = button.indexOf('Actions.insertAsync(actionDoc)');
|
|
assert.ok(guard > 0 && guard < triggerInsert && triggerInsert < insert);
|
|
assert.match(
|
|
button.slice(guard, insert),
|
|
/allowIsBoardMemberWithWriteAccess\(this\.userId, destination\)/,
|
|
);
|
|
});
|
|
|
|
test('negative: denied rule creation is attributed and throws before insertion', () => {
|
|
const guard = button.match(
|
|
/if \(actionDoc\.boardId !== boardId\) \{[\s\S]*?\n \}/,
|
|
);
|
|
assert.ok(guard);
|
|
assert.match(guard[0], /tripCanary\('rule\.cross-board-write'/);
|
|
assert.match(guard[0], /throw new Meteor\.Error\(\s*'not-authorized'/);
|
|
});
|
|
|
|
test('legacy cross-board actions are checked before destination lookups', () => {
|
|
const gate = helper.indexOf('if (crossBoardActions.includes(action.actionType)');
|
|
const firstListLookup = helper.indexOf('ReactiveCache.getList(', gate);
|
|
assert.ok(gate > 0 && gate < firstListLookup);
|
|
assert.match(
|
|
helper.slice(gate, firstListLookup),
|
|
/allowIsBoardMemberWithWriteAccess\(activity\.userId, destination\)/,
|
|
);
|
|
});
|
|
|
|
test('move, link and bulk-move actions all use the execution gate', () => {
|
|
for (const type of [
|
|
'moveCardToTop',
|
|
'moveCardToBottom',
|
|
'linkCard',
|
|
'moveAllCardsInList',
|
|
]) {
|
|
assert.match(helper, new RegExp(`'${type}'`), `${type} must be gated`);
|
|
}
|
|
});
|
|
|
|
test('negative: REST creation and editing cannot retain a supplied destination', () => {
|
|
assert.match(rest, /const STRIP = \['_id', 'boardId'/);
|
|
assert.match(rest, /Actions\.insertAsync\(\{ \.\.\.strip\(action\), boardId: paramBoardId \}\)/);
|
|
assert.match(rest, /writeRuleComponent\(rule, 'action', \{ \.\.\.strip\(req\.body\.action\), boardId: paramBoardId \}, \{ patch: true \}\)/);
|
|
});
|
|
|
|
test('browser fixtures remove rule documents for each discarded board', () => {
|
|
const cleanup = playwrightDb.match(/function cleanup\([\s\S]*?\n\}/);
|
|
assert.ok(cleanup);
|
|
for (const collection of ['rules', 'triggers', 'actions']) {
|
|
assert.match(
|
|
cleanup[0],
|
|
new RegExp(`collection: '${collection}'.*filter: \\{ boardId \\}`),
|
|
`${collection} must not leak into later browser tests`,
|
|
);
|
|
}
|
|
});
|
|
|
|
// RuleBleed sibling (2026-10-02): an action without a boardId queried lists
|
|
// and swimlanes with { boardId: undefined } - any board, by title - and its
|
|
// destination went unchecked. It acts on the activity's board now.
|
|
test('an action without a boardId acts on the activity\'s own board', () => {
|
|
const src = require('fs').readFileSync(require('path').join(__dirname, '..', 'server/rulesHelper.js'), 'utf8');
|
|
const at = src.indexOf(' async performAction(activity, action, ruleRun) {');
|
|
const body = src.slice(at, src.indexOf('const crossBoardActions', at));
|
|
assert.match(body, /if \(!action\.boardId\) \{\s*action = Object\.assign\(Object\.create\(Object\.getPrototypeOf\(action\)\), action, \{ boardId \}\);/);
|
|
});
|
|
|
|
console.log(`\n${passed} tests passed`);
|