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

395 lines
13 KiB
JavaScript

import { parseDueAt, checklistWithItems } from '/server/lib/checklistDeadlines';
import { Meteor } from 'meteor/meteor';
import { WebApp } from 'meteor/webapp';
import { Authentication } from '/server/authentication';
import { sendJsonResult } from '/server/apiMiddleware';
import { ReactiveCache } from '/imports/reactiveCache';
import { requireBoardMutation } from '/models/lib/boardMutationGuard';
import Checklists from '/models/checklists';
import ChecklistItems from '/models/checklistItems';
import Activities from '/models/activities';
import { ensureIndex } from '/server/lib/mongoStartup';
import { backfillBoardIdFromCard } from '/server/lib/denormalizeBoardId';
const { deferSyncChecklistRecording } = require('/server/lib/syncRecordingScope');
Meteor.methods({
async moveChecklist(checklistId, newCardId) {
check(checklistId, String);
check(newCardId, String);
if (!this.userId) {
throw new Meteor.Error('not-authorized', 'You must be logged in.');
}
const checklist = await ReactiveCache.getChecklist(checklistId);
if (!checklist) {
throw new Meteor.Error('checklist-not-found', 'Checklist not found');
}
const newCard = await ReactiveCache.getCard(newCardId);
if (!newCard) {
throw new Meteor.Error('card-not-found', 'Target card not found');
}
const sourceCard = await ReactiveCache.getCard(checklist.cardId);
const sourceBoard = sourceCard && await ReactiveCache.getBoard(sourceCard.boardId);
const targetBoard = await ReactiveCache.getBoard(newCard.boardId);
requireBoardMutation(this.userId, sourceBoard, 'moveChecklist:source', Meteor);
requireBoardMutation(this.userId, targetBoard, 'moveChecklist:destination', Meteor);
// Both cards change: the caller may edit each, which for an assigned-only
// member means their own (GHSA-r4gm-mjj9-g3x8).
const { canEditCardOrLinkedCard } = require('/server/lib/linkedCardPermission');
if (!sourceCard || !(await canEditCardOrLinkedCard(this.userId, sourceCard, sourceBoard)) ||
!(await canEditCardOrLinkedCard(this.userId, newCard, targetBoard))) {
throw new Meteor.Error('not-authorized', 'You cannot change these cards.');
}
const activities = await ReactiveCache.getActivities({ checklistId });
for (const activity of activities) {
await Activities.updateAsync(activity._id, {
$set: {
cardId: newCardId,
},
});
}
const checklistItems = await ReactiveCache.getChecklistItems({ checklistId });
for (const checklistItem of checklistItems) {
await ChecklistItems.updateAsync(checklistItem._id, {
$set: {
cardId: newCardId,
},
});
}
await Checklists.updateAsync(checklistId, {
$set: {
cardId: newCardId,
},
});
return checklistId;
},
});
// --- Denormalized boardId (see models/checklists.js schema) -----------------
// Set boardId from the card on insert, and re-sync it whenever the checklist is
// moved to another card, so the board publication can filter checklists by a
// single reactive cursor on boardId and still see checklists on newly added
// cards. Server-authoritative: the board publication runs on the server, so the
// server document carrying boardId is what matters.
Checklists.before.insert(async (userId, doc) => {
if (!doc.boardId && doc.cardId) {
const card = await ReactiveCache.getCard(doc.cardId);
if (card) {
doc.boardId = card.boardId;
}
}
});
Checklists.before.update(async (userId, doc, fieldNames, modifier) => {
const newCardId = modifier && modifier.$set && modifier.$set.cardId;
if (newCardId && newCardId !== doc.cardId) {
const card = await ReactiveCache.getCard(newCardId);
if (card) {
modifier.$set.boardId = card.boardId;
}
}
});
Meteor.startup(async () => {
await ensureIndex(Checklists, { modifiedAt: -1 });
await ensureIndex(Checklists, { cardId: 1, createdAt: 1 });
await ensureIndex(Checklists, { boardId: 1 });
// Backfill existing rows in the background (memory-safe, idempotent) so it
// never blocks or OOMs startup. New checklists already get boardId on insert.
Meteor.defer(() => {
backfillBoardIdFromCard(Checklists, { label: 'checklists' });
});
});
Checklists.after.insert(async (userId, doc) => {
// A durable rule addChecklist writes this activity from its saved plan.
if (deferSyncChecklistRecording('checklistActivity', doc)) return;
const card = await ReactiveCache.getCard(doc.cardId);
if (!card) {
console.warn('[Checklists.after.insert] Card not found for cardId:', doc.cardId, '— skipping addChecklist activity.');
return;
}
await Activities.insertAsync({
userId,
activityType: 'addChecklist',
cardId: doc.cardId,
boardId: card.boardId,
checklistId: doc._id,
checklistName: doc.title,
listId: card.listId,
swimlaneId: card.swimlaneId,
});
});
Checklists.before.remove(async (userId, doc) => {
// A durable rule removeChecklist writes this activity from its saved plan.
if (deferSyncChecklistRecording('checklistActivity', doc)) return;
try {
// #1598: keep the checklist's timestamped activity trail.
// When a whole list/card is deleted, the parent card may already be gone by
// the time its checklists are removed (cascade delete). Skip the activity
// then instead of dereferencing an undefined card, which would throw an
// unhandled rejection and crash SyncedCron.
const card = await ReactiveCache.getCard(doc.cardId);
if (!card) {
console.warn('[Checklists.before.remove] Card not found for cardId:', doc.cardId, '— skipping removeChecklist activity.');
return;
}
await Activities.insertAsync({
userId,
activityType: 'removeChecklist',
cardId: doc.cardId,
boardId: card.boardId,
checklistId: doc._id,
checklistName: doc.title,
listId: card.listId,
swimlaneId: card.swimlaneId,
});
} catch (e) {
console.error('[Checklists.before.remove] Error while processing checklist deletion for doc._id:', doc._id, e);
}
});
WebApp.handlers.get(
'/api/boards/:boardId/cards/:cardId/checklists',
async function(req, res) {
const paramBoardId = req.params.boardId;
const paramCardId = req.params.cardId;
await Authentication.checkBoardAccess(req.userId, paramBoardId);
const card = await ReactiveCache.getCard({
_id: paramCardId,
boardId: paramBoardId,
});
if (!card) {
sendJsonResult(res, {
code: 404,
data: { error: 'Card not found or does not belong to the specified board' },
});
return;
}
const checklists = await Promise.all((await ReactiveCache.getChecklists({ cardId: paramCardId }, { sort: ['sort'] }))
.map(doc => checklistWithItems(doc, ReactiveCache)));
if (checklists) {
sendJsonResult(res, {
code: 200,
data: checklists,
});
} else {
sendJsonResult(res, {
code: 500,
});
}
},
);
WebApp.handlers.get(
'/api/boards/:boardId/cards/:cardId/checklists/:checklistId',
async function(req, res) {
const paramBoardId = req.params.boardId;
const paramChecklistId = req.params.checklistId;
const paramCardId = req.params.cardId;
await Authentication.checkBoardAccess(req.userId, paramBoardId);
const card = await ReactiveCache.getCard({
_id: paramCardId,
boardId: paramBoardId,
});
if (!card) {
sendJsonResult(res, {
code: 404,
data: { error: 'Card not found or does not belong to the specified board' },
});
return;
}
const checklist = await ReactiveCache.getChecklist({
_id: paramChecklistId,
cardId: paramCardId,
});
if (checklist) {
sendJsonResult(res, {
code: 200,
data: await checklistWithItems(checklist, ReactiveCache),
});
} else {
sendJsonResult(res, {
code: 500,
});
}
},
);
WebApp.handlers.post(
'/api/boards/:boardId/cards/:cardId/checklists',
async function(req, res) {
const paramBoardId = req.params.boardId;
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
const paramCardId = req.params.cardId;
const card = await ReactiveCache.getCard({
_id: paramCardId,
boardId: paramBoardId,
});
if (!card) {
sendJsonResult(res, {
code: 404,
data: { error: 'Card not found or does not belong to the specified board' },
});
return;
}
const deadline = parseDueAt(req.body);
if (deadline.error) {
sendJsonResult(res, { code: 400, data: { error: deadline.error } });
return;
}
const id = await Checklists.insertAsync({
title: req.body.title,
...(deadline.dueAt ? { dueAt: deadline.dueAt } : {}),
cardId: paramCardId,
sort: 0,
});
if (id) {
let items = req.body.items || [];
if (typeof items === 'string') {
if (items === '') {
items = [];
} else {
items = [items];
}
}
for (const [idx, item] of items.entries()) {
await ChecklistItems.insertAsync({
cardId: paramCardId,
checklistId: id,
title: item,
sort: idx,
});
}
sendJsonResult(res, {
code: 200,
data: {
_id: id,
},
});
} else {
sendJsonResult(res, {
code: 400,
});
}
},
);
// #1037: GET/POST/DELETE were exposed for a checklist but there was no way to
// rename one over the REST API - a client had to delete and re-create it,
// losing the checklistId and its items. Mirrors the DELETE handler right below
// it (same lookup / auth), and lists.js's own PUT for the same "edit the
// title of a thing on the board" shape. `title` and optional `dueAt` are accepted: the other
// per-checklist toggles (hideCheckedChecklistItems, resetInterval, etc.) are
// not exposed anywhere over the REST API yet and are out of scope here.
WebApp.handlers.put(
'/api/boards/:boardId/cards/:cardId/checklists/:checklistId',
async function(req, res) {
const paramBoardId = req.params.boardId;
const paramCardId = req.params.cardId;
const paramChecklistId = req.params.checklistId;
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
const card = await ReactiveCache.getCard({
_id: paramCardId,
boardId: paramBoardId,
});
if (!card) {
sendJsonResult(res, {
code: 404,
data: { error: 'Card not found or does not belong to the specified board' },
});
return;
}
const checklist = await ReactiveCache.getChecklist({
_id: paramChecklistId,
cardId: paramCardId,
});
if (!checklist) {
sendJsonResult(res, {
code: 404,
data: { error: 'Checklist not found or does not belong to the specified card' },
});
return;
}
const deadline = parseDueAt(req.body);
const hasTitle = Object.prototype.hasOwnProperty.call(req.body || {}, 'title');
if (deadline.error || (hasTitle && (typeof req.body.title !== 'string' || !req.body.title.trim())) || (!hasTitle && !Object.prototype.hasOwnProperty.call(deadline, 'dueAt'))) {
sendJsonResult(res, { code: 400, data: { error: deadline.error || 'title or dueAt is required' } });
return;
}
const modifier = {};
if (hasTitle) modifier.$set = { title: req.body.title };
if (Object.prototype.hasOwnProperty.call(deadline, 'dueAt')) {
if (deadline.dueAt === null) modifier.$unset = { dueAt: '' };
else modifier.$set = { ...modifier.$set, dueAt: deadline.dueAt };
}
await Checklists.direct.updateAsync({ _id: paramChecklistId, cardId: paramCardId }, modifier);
sendJsonResult(res, {
code: 200,
data: {
_id: paramChecklistId,
},
});
},
);
WebApp.handlers.delete(
'/api/boards/:boardId/cards/:cardId/checklists/:checklistId',
async function(req, res) {
const paramBoardId = req.params.boardId;
const paramCardId = req.params.cardId;
const paramChecklistId = req.params.checklistId;
await Authentication.checkBoardWriteAccess(req.userId, paramBoardId);
const card = await ReactiveCache.getCard({
_id: paramCardId,
boardId: paramBoardId,
});
if (!card) {
sendJsonResult(res, {
code: 404,
data: { error: 'Card not found or does not belong to the specified board' },
});
return;
}
const checklist = await ReactiveCache.getChecklist({
_id: paramChecklistId,
cardId: paramCardId,
});
if (!checklist) {
sendJsonResult(res, {
code: 404,
data: { error: 'Checklist not found or does not belong to the specified card' },
});
return;
}
await Checklists.removeAsync({ _id: paramChecklistId });
sendJsonResult(res, {
code: 200,
data: {
_id: paramChecklistId,
},
});
},
);