Files
wekan/models/lib/boardCardScope.js
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

94 lines
3.8 KiB
JavaScript

'use strict';
// A destination pointer is not read permission. Foreign deposit content is
// published beneath its own reactive, authorized board cursor instead.
function boardScopeIds(board) {
if (!board || typeof board._id !== 'string' || board._id.length === 0) return [];
return [board._id];
}
// Spread this into a card selector: `{ ...boardCardScope(board), archived: false }`.
function boardCardScope(board) {
return { boardId: { $in: boardScopeIds(board) } };
}
// Is this user an ASSIGNED-ONLY member of this board? Three board-member flags
// mean it — isReadAssignedOnly, isNormalAssignedOnly, isCommentAssignedOnly — and
// all three carry the same rule: the member may only see the cards they are
// assigned to.
//
// A user who is not an active member of the board is NOT restricted here. That is
// deliberate and matches the `board` publication: someone reaching a public board
// without membership has no member document to carry a flag, and the restriction
// is a narrowing of what a MEMBER sees, not the board's visibility rule.
function isAssignedOnlyMember(board, userId) {
if (!userId || !board || !Array.isArray(board.members)) return false;
const member = board.members.find(
m => m && m.userId === userId && m.isActive === true,
);
if (!member) return false;
return !!(
member.isNormalAssignedOnly ||
member.isCommentAssignedOnly ||
member.isReadAssignedOnly
);
}
// The card-selector clause that narrows a board's cards to the ones an
// assigned-only member may see, or null when the member is not restricted.
function assignedOnlyCardScope(board, userId) {
if (!isAssignedOnlyMember(board, userId)) return null;
return { assignees: { $in: [userId] } };
}
// Merge a server-side scope into a card selector the CLIENT supplied.
//
// Keep both selectors as ordinary MongoDB conjuncts. This also prevents a client
// key from replacing a server-enforced scope key.
function mergeCardScope(clientSelector, scope) {
const client = clientSelector || {};
const server = scope || {};
return { $and: [client, server] };
}
// May this user copy (or move) content out of this board? A copy shows the
// content in a board the user controls, so an assigned-only member may copy
// only a card assigned to them - never a whole list or swimlane, which holds
// cards they cannot see. Pass the card for a card copy, nothing for a container.
function mayCopyFromBoard(board, userId, card) {
return assignedOnlyAllowsCard(board, userId, card);
}
// The card half of a board role, for any action on one card - reading it,
// commenting on it, running a rule on it (GHSA-r4gm-mjj9-g3x8: board roles
// apply to every view). Everyone but an assigned-only member passes; they
// pass only for a card assigned to them. The card must carry `assignees`.
function assignedOnlyAllowsCard(board, userId, card) {
if (!isAssignedOnlyMember(board, userId)) return true;
return !!card && Array.isArray(card.assignees) && card.assignees.includes(userId);
}
// The subtasks a copy of a card carries along (AssignedBleed copy sibling,
// 2026-10-03): only those the copier could read and copy themselves. A copy
// took every subtask, so an assigned-only member copying a card assigned to
// them got copies of its subtasks assigned to others, and of subtasks on
// boards they cannot read at all. `boardOf(boardId)` returns a subtask's
// board (or null); `canRead(userId, board)` is models/lib/boardVisibility.
function copyableSubtasks(subtasks, userId, boardOf, canRead) {
return (subtasks || []).filter(subtask => {
const board = subtask && boardOf(subtask.boardId);
return !!board && canRead(userId, board) && mayCopyFromBoard(board, userId, subtask);
});
}
module.exports = {
mayCopyFromBoard,
assignedOnlyAllowsCard,
copyableSubtasks,
boardScopeIds,
boardCardScope,
isAssignedOnlyMember,
assignedOnlyCardScope,
mergeCardScope,
};