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

63 lines
3.9 KiB
JavaScript

// #2026 / #1377: the all-boards activity feed (models/lib/activityFeed.js).
import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import { DDPRateLimiter } from 'meteor/ddp-rate-limiter';
import Activities from '/models/activities';
import Cards from '/models/cards';
import Lists from '/models/lists';
import Swimlanes from '/models/swimlanes';
import Checklists from '/models/checklists';
import ChecklistItems from '/models/checklistItems';
import CardComments from '/models/cardComments';
import { ReactiveCache } from '/imports/reactiveCache';
import { getFeatureFlags } from '/models/lib/featureFlags';
import { visibleAllBoards } from '/server/allBoardsFacets';
const { isAssignedOnlyMember } = require('/models/lib/boardCardScope');
const { feedEntry, visibleActivities, cleanLimit } = require('/models/lib/activityFeed');
Meteor.methods({
async allBoardsActivityFeed(options) {
check(options, Match.Optional({ limit: Match.Optional(Number), before: Match.Optional(Date) }));
if (!this.userId) throw new Meteor.Error('not-authorized');
if (getFeatureFlags().disableActivities) return [];
const setting = await ReactiveCache.getCurrentSetting();
if (setting && setting.hideBoardActivitiesOnAllBoards) return [];
const user = await ReactiveCache.getUser(this.userId);
if (!user) return [];
const limit = cleanLimit(options && options.limit);
const boards = await visibleAllBoards(user, { title: 1, slug: 1, members: 1, labels: 1 });
const boardIds = boards.map(b => b._id);
const assignedOnlyBoardIds = boards.filter(b => isAssignedOnlyMember(b, this.userId)).map(b => b._id);
const assignedCardIds = assignedOnlyBoardIds.length
// Assigned to them, as on the board itself - not merely a card member
// (GHSA-r4gm-mjj9-g3x8).
? (await Cards.find({ boardId: { $in: assignedOnlyBoardIds }, assignees: this.userId },
{ fields: { _id: 1 } }).fetchAsync()).map(c => c._id) : [];
const selector = { boardId: { $in: boardIds } };
if (options && options.before) selector.createdAt = { $lt: options.before };
// What the sentence names (models/lib/activityFeed.js feedParams): ids
// and a renamed thing's new title - never a field's value.
const raw = await Activities.find(selector, { sort: { createdAt: -1 }, limit: limit * 3,
fields: { activityType: 1, createdAt: 1, boardId: 1, cardId: 1, listId: 1, userId: 1, oldListId: 1, swimlaneId: 1,
oldSwimlaneId: 1, checklistId: 1, checklistItemId: 1, commentId: 1, attachmentName: 1, labelId: 1, memberId: 1,
assigneeId: 1, oldBoardId: 1, title: 1 } }).fetchAsync();
const activities = visibleActivities(raw, { assignedOnlyBoardIds, assignedCardIds }).slice(0, limit);
const ids = (...fields) => [...new Set(activities.flatMap(a => fields.map(field => a[field])).filter(id => typeof id === 'string' && id))];
const byTitle = async (collection, fields, projection = { title: 1 }) => new Map((await collection.find(
{ _id: { $in: ids(...fields) } }, { fields: projection }).fetchAsync()).map(doc => [doc._id, doc]));
const cards = await byTitle(Cards, ['cardId']);
const lists = await byTitle(Lists, ['listId', 'oldListId']);
const swimlanes = await byTitle(Swimlanes, ['swimlaneId', 'oldSwimlaneId']);
const checklists = await byTitle(Checklists, ['checklistId']);
const checklistItems = await byTitle(ChecklistItems, ['checklistItemId']);
const comments = await byTitle(CardComments, ['commentId'], { text: 1 });
const users = await byTitle(Meteor.users, ['userId', 'memberId', 'assigneeId'], { username: 1 });
const byId = new Map(boards.map(b => [b._id, b]));
return activities.map(a => feedEntry(a, { boards: byId, cards, lists, users, swimlanes, checklists, checklistItems,
comments, viewerId: this.userId })).filter(Boolean);
},
});
DDPRateLimiter.addRule({ type: 'method', name: 'allBoardsActivityFeed', connectionId: () => true }, 20, 10000);