Files
wekan/tests/linkedWritePolicy.test.cjs
T
Lauri Ojansivu 5b2ed17e6b Board role permissions apply to every board view and every path to a card.
AssignedBleed follow-up, GHSA-r4gm-mjj9-g3x8. An assigned-only member
(isNormalAssignedOnly, isCommentAssignedOnly, isReadAssignedOnly, and custom
roles through those flags) sees only the cards assigned to them. The Board
Email View checked board.isVisibleBy() alone, so it published the title,
description and email metadata of every card in a list or label, counted
them, and searched them. It now merges assignedOnlyCardScope into its folder
and search selector for the page and the count, and a reply on another card
is refused.

An audit of every path that returns or changes a card found the same shape -
"a member of the board, so every card of it" - elsewhere, all fixed here:

- reads: the board publication's ancestor cards, linked source cards with
  their subtasks and dependency targets, and comment reactions; All Boards
  tile counts; a board's activities from linked boards; the Chat view and
  the All Boards feed, which also let card MEMBERS through (assignees is the
  rule); My Attachments' card; GET /api/user/cards; position history of a
  card; the cross-board subtask picker; Scrum rollover counts; and the
  notification publications, which kept sending the full documents of cards
  named in old notifications - also to members removed from the board;
- writes on a card the member cannot see: the canonical
  canEditCardOrLinkedCard / editableCardIds (every Cards.allow update,
  checklists, items, attachments, text notes, custom fields, the shared
  description, card methods) now ask the card - the role's `write` is a
  board answer, and the card is read when a caller passed it without
  assignees; DDP and REST comments, button rules on a card, checklist moves,
  issue state, watching, the card-opened webhook, moveBoardObjects,
  moveSwimlane and attachment moves;
- REST writes: checkBoardWriteAccess refuses assigned-only members, as
  checkBoardAccess already does for reads - those routes act on any card,
  list or swimlane by id. The GHSA-f396 canary still fires for a role
  without the write capability.

A refusal no view would produce is recorded under AssignedBleed in Admin
Panel -> Problems (authz.assigned, medium: never disables); opening a view,
searching and REST calls are narrowed or refused without a record.

tests/boardRoleViews.test.cjs runs the Email View selector, pins every path
above, and fails when any server file that serves card data has no role
rule and no stated exemption; the "assignee or card member" rule is
rejected anywhere in server/ and models/. server/lib/tests/editableCardIds
adds an assigned-only case for both edit checks (meteor test; not run here).
Seven guards that pinned the old lines now pin the new ones.

Thanks to crypto-nidh, binary-lover and xet7 !
2026-10-16 13:03:34 +03:00

58 lines
4.0 KiB
JavaScript

'use strict';
// Hall of Fame regression coverage: LinkedWriteBleed.
const { test } = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const vm = require('node:vm');
const { sourceRoleBlocksDelegation } = require('../models/lib/linkedWritePolicy');
const { BOARD_ROLES, ROLE_FLAGS, roleCan, memberCan } = require('../models/lib/boardRoleCapabilities');
test('live links cannot promote explicit non-writing source roles', async () => {
const text = fs.readFileSync('server/lib/linkedCardPermission.js', 'utf8');
for (const role of BOARD_ROLES) {
const member = { userId: 'u', isActive: true, [ROLE_FLAGS[role] || 'normal']: true };
const source = { _id: 'A', members: [member] };
assert.equal(sourceRoleBlocksDelegation('u', source), !roleCan(role, 'write'));
// An assigned-only role is decided by the card first, before any link
// (GHSA-r4gm-mjj9-g3x8, tests/boardRoleViews.test.cjs); this test is about
// what a link may delegate.
if (/assigned-only/.test(role)) continue;
const logs = [], context = {
sourceRoleBlocksDelegation, recordLinkedWriteDenial: source => logs.push(source),
allowIsBoardMemberWithWriteAccess: (id, board) => Boolean(board && memberCan(board.members, id, 'write')),
canUserSeeBoard: async () => true,
// #4527: the card's list is asked first; these lists make no exception,
// so the source role alone decides, as this test is about.
listException: async () => undefined,
require: name => (/boardCardScope/.test(name) ? require('../models/lib/boardCardScope') : { exceptionFor: () => undefined }),
Boards: { findOneAsync: async () => source, find: () => ({ fetchAsync: async () => [{ members: [{ userId: 'u', isActive: true, isAdmin: true }] }] }) },
Cards: { find: () => ({ fetchAsync: async () => [{ boardId: 'self-owned' }] }) },
};
vm.runInNewContext(text.replace(/^import .*;\n/gm, '').replace(/^export async function/gm, 'async function'), context);
assert.equal(await context.canEditCardOrLinkedCard('u', { _id: 'card', boardId: 'A' }), roleCan(role, 'write'));
assert.equal(logs.length, roleCan(role, 'write') ? 0 : 1);
const count = logs.length;
assert.equal(await context.canEditCardOrLinkedCard('u', { _id: 'card', boardId: 'A' }, source, { recordDenial: false }), roleCan(role, 'write'));
assert.equal(logs.length, count, 'read-side capability checks must not emit write-denial events');
}
});
test('negative: method, DDP insert and link-pointer updates enforce source write access', () => {
const methods = fs.readFileSync('server/models/cards.js', 'utf8');
const at = methods.indexOf('async function createLinkedCardFor(');
const body = methods.slice(at, methods.indexOf('Meteor.methods({', at));
assert.doesNotMatch(body, /allowIsBoardMember\(/);
assert.match(body, /allowIsBoardMemberWithWriteAccess\(userId, sourceBoard\)/);
// An assigned-only member links only cards assigned to them.
assert.match(body, /isAssignedOnlyMember\(sourceBoard, userId\) && !\(sourceCard\.assignees \|\| \[\]\)\.includes\(userId\)/);
// The method and the REST route (linkedId) both use that one rule; the REST
// route used to check only read access and clone the whole source card.
assert.match(methods, /return createLinkedCardFor\(this\.userId, [^)]*'createLinkedCard'\)/);
assert.match(methods, /await createLinkedCardFor\(req\.userId, [\s\S]*?'rest:card-link'\)/);
const rest = methods.slice(methods.indexOf("if (req.body.linkedId) {"), methods.indexOf("const linkedCard = await ReactiveCache.getCard(linkedNewId);"));
assert.doesNotMatch(rest, /checkBoardAccess|\.link\(/);
const ddp = fs.readFileSync('server/permissions/cards.js', 'utf8');
assert.equal((ddp.match(/await denyUnauthorizedCardLink\(/g) || []).length, 2);
assert.match(ddp, /allowIsBoardMemberWithWriteAccess\(userId, board\)/);
const helper = fs.readFileSync('server/lib/linkedCardPermission.js', 'utf8');
assert.ok(helper.indexOf('sourceRoleBlocksDelegation(userId, sourceBoard)') < helper.indexOf('const links ='));
});