Files
wekan/server/methods/positionHistory.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

338 lines
9.6 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { check } from 'meteor/check';
import PositionHistory from '/models/positionHistory';
import Swimlanes from '/models/swimlanes';
import Lists from '/models/lists';
import Cards from '/models/cards';
import { ReactiveCache } from '/imports/reactiveCache';
import { canReadBoard } from '/models/lib/boardVisibility';
const { isAssignedOnlyMember, mayCopyFromBoard } = require('/models/lib/boardCardScope');
async function assertCanReadBoard(userId, boardId) {
const board = await ReactiveCache.getBoard(boardId);
if (!canReadBoard(userId, board)) {
throw new Meteor.Error('not-authorized', 'You do not have access to this board.');
}
return board;
}
// An assigned-only member sees the history of the cards assigned to them, and
// of the board's swimlanes and lists, never of another member's cards.
async function assignedOnlyHistoryScope(userId, board) {
if (!isAssignedOnlyMember(board, userId)) return null;
const cards = await ReactiveCache.getCards({ boardId: board._id, assignees: userId }, { fields: { _id: 1 } });
return { $or: [{ entityType: { $ne: 'card' } }, { entityId: { $in: (cards || []).map(card => card._id) } }] };
}
/**
* Server-side methods for position history tracking
*/
Meteor.methods({
/**
* Track original position for a swimlane
*/
async 'positionHistory.trackSwimlane'(swimlaneId) {
check(swimlaneId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const swimlane = await Swimlanes.findOneAsync(swimlaneId);
if (!swimlane) {
throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
}
await assertCanReadBoard(this.userId, swimlane.boardId);
return swimlane.trackOriginalPosition();
},
/**
* Track original position for a list
*/
async 'positionHistory.trackList'(listId) {
check(listId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const list = await Lists.findOneAsync(listId);
if (!list) {
throw new Meteor.Error('list-not-found', 'List not found');
}
await assertCanReadBoard(this.userId, list.boardId);
return list.trackOriginalPosition();
},
/**
* Track original position for a card
*/
async 'positionHistory.trackCard'(cardId) {
check(cardId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const card = await Cards.findOneAsync(cardId);
if (!card) {
throw new Meteor.Error('card-not-found', 'Card not found');
}
// ...and the card by the board role, as getCardDescription does
// (GHSA-r4gm-mjj9-g3x8): an assigned-only member's own cards only.
const cardBoard = await assertCanReadBoard(this.userId, card.boardId);
if (!mayCopyFromBoard(cardBoard, this.userId, card)) {
throw new Meteor.Error('not-authorized', 'You do not have access to this card.');
}
return card.trackOriginalPosition();
},
/**
* Get original position for a swimlane
*/
async 'positionHistory.getSwimlaneOriginalPosition'(swimlaneId) {
check(swimlaneId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const swimlane = await Swimlanes.findOneAsync(swimlaneId);
if (!swimlane) {
throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
}
await assertCanReadBoard(this.userId, swimlane.boardId);
return swimlane.getOriginalPosition();
},
/**
* Get original position for a list
*/
async 'positionHistory.getListOriginalPosition'(listId) {
check(listId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const list = await Lists.findOneAsync(listId);
if (!list) {
throw new Meteor.Error('list-not-found', 'List not found');
}
await assertCanReadBoard(this.userId, list.boardId);
return list.getOriginalPosition();
},
/**
* Get original position for a card
*/
async 'positionHistory.getCardOriginalPosition'(cardId) {
check(cardId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const card = await Cards.findOneAsync(cardId);
if (!card) {
throw new Meteor.Error('card-not-found', 'Card not found');
}
// ...and the card by the board role, as getCardDescription does
// (GHSA-r4gm-mjj9-g3x8): an assigned-only member's own cards only.
const cardBoard = await assertCanReadBoard(this.userId, card.boardId);
if (!mayCopyFromBoard(cardBoard, this.userId, card)) {
throw new Meteor.Error('not-authorized', 'You do not have access to this card.');
}
return card.getOriginalPosition();
},
/**
* Check if a swimlane has moved from its original position
*/
async 'positionHistory.hasSwimlaneMoved'(swimlaneId) {
check(swimlaneId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const swimlane = await Swimlanes.findOneAsync(swimlaneId);
if (!swimlane) {
throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
}
await assertCanReadBoard(this.userId, swimlane.boardId);
return swimlane.hasMovedFromOriginalPosition();
},
/**
* Check if a list has moved from its original position
*/
async 'positionHistory.hasListMoved'(listId) {
check(listId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const list = await Lists.findOneAsync(listId);
if (!list) {
throw new Meteor.Error('list-not-found', 'List not found');
}
await assertCanReadBoard(this.userId, list.boardId);
return list.hasMovedFromOriginalPosition();
},
/**
* Check if a card has moved from its original position
*/
async 'positionHistory.hasCardMoved'(cardId) {
check(cardId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const card = await Cards.findOneAsync(cardId);
if (!card) {
throw new Meteor.Error('card-not-found', 'Card not found');
}
// ...and the card by the board role, as getCardDescription does
// (GHSA-r4gm-mjj9-g3x8): an assigned-only member's own cards only.
const cardBoard = await assertCanReadBoard(this.userId, card.boardId);
if (!mayCopyFromBoard(cardBoard, this.userId, card)) {
throw new Meteor.Error('not-authorized', 'You do not have access to this card.');
}
return card.hasMovedFromOriginalPosition();
},
/**
* Get original position description for a swimlane
*/
async 'positionHistory.getSwimlaneDescription'(swimlaneId) {
check(swimlaneId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const swimlane = await Swimlanes.findOneAsync(swimlaneId);
if (!swimlane) {
throw new Meteor.Error('swimlane-not-found', 'Swimlane not found');
}
await assertCanReadBoard(this.userId, swimlane.boardId);
return swimlane.getOriginalPositionDescription();
},
/**
* Get original position description for a list
*/
async 'positionHistory.getListDescription'(listId) {
check(listId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const list = await Lists.findOneAsync(listId);
if (!list) {
throw new Meteor.Error('list-not-found', 'List not found');
}
await assertCanReadBoard(this.userId, list.boardId);
return list.getOriginalPositionDescription();
},
/**
* Get original position description for a card
*/
async 'positionHistory.getCardDescription'(cardId) {
check(cardId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const card = await Cards.findOneAsync(cardId);
if (!card) {
throw new Meteor.Error('card-not-found', 'Card not found');
}
const cardBoard = await assertCanReadBoard(this.userId, card.boardId);
if (!mayCopyFromBoard(cardBoard, this.userId, card)) {
throw new Meteor.Error('not-authorized', 'You do not have access to this card.');
}
return card.getOriginalPositionDescription();
},
/**
* Get all position history for a board
*/
async 'positionHistory.getBoardHistory'(boardId) {
check(boardId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const board = await assertCanReadBoard(this.userId, boardId);
const scope = await assignedOnlyHistoryScope(this.userId, board);
return PositionHistory.find({
boardId: boardId,
...(scope || {}),
}, {
sort: { createdAt: -1 }
}).fetchAsync();
},
/**
* Get position history by entity type for a board
*/
async 'positionHistory.getBoardHistoryByType'(boardId, entityType) {
check(boardId, String);
check(entityType, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const board = await assertCanReadBoard(this.userId, boardId);
const scope = await assignedOnlyHistoryScope(this.userId, board);
if (!['swimlane', 'list', 'card'].includes(entityType)) {
throw new Meteor.Error('invalid-entity-type', 'Entity type must be swimlane, list, or card');
}
return PositionHistory.find({
boardId: boardId,
entityType: entityType,
...(scope || {}),
}, {
sort: { createdAt: -1 }
}).fetchAsync();
},
});