Files
wekan/server/permissions/rules.js
T
Lauri Ojansivu 509f1d97fc Refuse a rule naming another board's trigger, and match rules on their own board (RepointBleed sibling).
Reviewing the legacy direct Rules writes: a board admin of their own board
could save a rule that named a trigger of a board they do not administer.
Only that board's own rules run on its activities, but the matcher took a
trigger's rule from Trigger.getRule() - whichever rule named it first - so
the other board's own rule could silently stop running. The matcher now
looks up the trigger's rule on the activity's board, and a DDP insert or
update of a rule naming another board's trigger is refused and recorded in
Admin Panel / Problems under RepointBleed (no client names one: the rule
editor creates the trigger on the rule's board first).

Tests: tests/repointBleed.test.cjs (the decision for insert, $set,
$addToSet and $push, the negatives, and the matcher's source), and a server
test that, without the change, accepted the foreign rule and lost the
victim board's rule.

Thanks to xet7 !
2026-10-03 10:26:48 +03:00

24 lines
942 B
JavaScript

import Boards from '/models/boards';
import Rules from '/models/rules';
import { allowIsBoardAdmin } from '/server/lib/utils';
import { denyBoardRepoint, denyForeignRuleTriggers } from '/server/lib/boardRepointGuard';
import Triggers from '/models/triggers';
Rules.allow({
async insert(userId, doc) {
return allowIsBoardAdmin(userId, await Boards.findOneAsync(doc.boardId));
},
async update(userId, doc) {
return allowIsBoardAdmin(userId, await Boards.findOneAsync(doc.boardId));
},
async remove(userId, doc) {
return allowIsBoardAdmin(userId, await Boards.findOneAsync(doc.boardId));
},
});
// RepointBleed: the allow rule above checks the board the document is on now;
// this refuses an update that moves it to another board.
Rules.deny(denyBoardRepoint('rules'));
// ...and one that names another board's trigger.
Rules.deny(denyForeignRuleTriggers(id => Triggers.findOneAsync(id, { fields: { boardId: 1 } })));