Files
wekan/server/lib/listPermissionGate.js
T
Lauri Ojansivu 3202a1d7ac A list's role exception also refuses deleting, archiving or moving it, and its swimlane.
Decided by the maintainer on 2026-11-18 (TODO.md). Deleting, archiving,
restoring or moving a list, and deleting, archiving or moving a
swimlane, does the same to the cards in it, so a list that refuses a
role write access (#4527) now refuses those too:

- lists.softRemove, lists.restore and moveList answer not-authorized;
- the REST list DELETE, archive, unarchive and move, and the REST
  swimlane DELETE, answer 403, recorded as ListLockBleed;
- moveSwimlane is refused when a list holding its cards, or bound to
  it, refuses the role (swimlaneRefusingListIds);
- client writes meet new Lists and Swimlanes deny rules, and the list
  menu no longer offers Archive list or Archive all cards in such a list.

Renaming, recolouring and reordering are not refused, and board admins
are never restricted.

tests/listLockStructure.test.cjs runs the swimlane gate and pins every
path; list-lock-bulk.e2e.js replays the REST cases. Sandboxed route
tests get a pass-through gate.

Thanks to xet7 !
2026-11-18 23:08:06 +02:00

121 lines
6.0 KiB
JavaScript

import Lists from '/models/lists';
import Cards from '/models/cards';
import { allowIsBoardMemberWithWriteAccess, allowIsBoardMemberCommentOnly } from '/server/lib/utils';
// #4527: the server half of per-list exceptions (models/lib/listPermissions.js
// decides). No side effects, so linkedCardPermission.js and the allow/deny
// rules in server/listPermissions.js can both import it.
const { exceptionFor } = require('/models/lib/listPermissions');
/** The list's exception for this user: true, false, or undefined (the board decides). */
export async function listException(userId, board, listId, capability) {
if (!userId || !board || typeof listId !== 'string' || !listId) return undefined;
const list = await Lists.findOneAsync(listId, { fields: { roleExceptions: 1, boardId: 1 } });
// A list on another board has no say here; that board's own rules decide.
if (!list || list.boardId !== board._id) return undefined;
return exceptionFor(board, list, userId, capability);
}
/** May this user add, edit or remove cards in this list? */
export async function canWriteInList(userId, board, listId) {
const exception = await listException(userId, board, listId, 'write');
if (exception !== undefined) return exception;
return allowIsBoardMemberWithWriteAccess(userId, board);
}
/** May this user comment on cards in this list? */
export async function canCommentInList(userId, board, listId) {
const exception = await listException(userId, board, listId, 'comment');
if (exception !== undefined) return exception;
return allowIsBoardMemberCommentOnly(userId, board);
}
/**
* The REST API's half: a list that refuses this user's role refuses the API
* too (403), so a restriction cannot be stepped round with a token. A list's
* GRANT does not open the API to a role the board does not let write.
*
* ListLockBleed (GHSA-4734-8vrg-8j3w): the checklist and checklist-item routes
* did not ask, so a member a list refused still wrote its cards' checklists
* over REST. Every REST write that names a card asks now
* (tests/listPermissions.test.cjs), and the refusal is recorded in Admin
* Panel -> Problems: no screen offers such a write, so it is an attempt.
*/
export async function assertListNotRefused(userId, board, listId, capability = 'write', source = 'rest:list-locked') {
if ((await listException(userId, board, listId, capability)) !== false) return;
try {
require('/server/lib/securityLog').record({ key: 'authz.list-locked', action: 'blocked', source, userId,
detail: `A REST ${capability} in a list whose exception refuses the caller's role.` });
} catch (e) { /* logging must never break the guard */ }
const { Meteor } = require('meteor/meteor');
const error = new Meteor.Error('Forbidden', 'Forbidden');
error.statusCode = 403;
throw error;
}
/**
* GHSA-83w9-74mx-7v83: a REST write that takes its cards from the BODY (the
* bulk delete and bulk label routes) names no list in its URL, so it has to ask
* for the list of every card it is given - all of them before the first write,
* so a refused selection changes nothing.
*/
export async function assertCardListsNotRefused(userId, board, cards, capability = 'write', source = 'rest:cards/bulk') {
const listIds = new Set((cards || []).map(card => card && card.listId).filter(Boolean));
for (const listId of listIds) {
if ((await listException(userId, board, listId, capability)) !== false) continue;
try {
require('/server/lib/securityLog').record({ key: 'authz.list-locked-bulk', action: 'blocked', source, userId,
detail: `A REST bulk ${capability} naming cards in a list whose exception refuses the caller's role.` });
} catch (e) { /* logging must never break the guard */ }
const { Meteor } = require('meteor/meteor');
const error = new Meteor.Error('Forbidden', 'Forbidden');
error.statusCode = 403;
throw error;
}
}
/**
* The Meteor methods' half (GHSA-83w9-74mx-7v83): server code writes past the
* Cards allow/deny rules in server/listPermissions.js, so a method that writes a
* card in - or into - a list asks here. Not recorded in Admin Panel -> Problems:
* Copy Card's destination picker and Multi-Selection reach these methods in
* ordinary use, so a refusal is not evidence of an attempt.
*/
export async function assertListsWritable(userId, board, listIds, capability = 'write') {
for (const listId of new Set((listIds || []).filter(Boolean))) {
if ((await listException(userId, board, listId, capability)) === false) {
const { Meteor } = require('meteor/meteor');
throw new Meteor.Error('not-authorized', 'This list does not allow your role to do that.');
}
}
}
/**
* Decided 2026-11-18 (TODO.md): deleting, archiving or moving a swimlane does
* the same to every card in it, so a list holding its cards - or bound to it -
* that refuses this user's role refuses the swimlane change too (#4527). The
* ids of the refusing lists; none for a board admin.
*/
export async function swimlaneRefusingListIds(userId, board, swimlaneId) {
if (!userId || !board || typeof swimlaneId !== 'string' || !swimlaneId) return [];
const withCards = await Cards.rawCollection().distinct('listId', { boardId: board._id, swimlaneId });
const bound = await Lists.rawCollection().distinct('_id', { boardId: board._id, swimlaneId });
const refusing = [];
for (const listId of new Set([...withCards, ...bound].filter(id => typeof id === 'string' && id))) {
if ((await listException(userId, board, listId, 'write')) === false) refusing.push(listId);
}
return refusing;
}
/** The method half: not-authorized, unrecorded (assertListsWritable). */
export async function assertSwimlaneListsWritable(userId, board, swimlaneId) {
await assertListsWritable(userId, board, await swimlaneRefusingListIds(userId, board, swimlaneId));
}
/** The REST half: 403, recorded as ListLockBleed (assertListNotRefused). */
export async function assertSwimlaneListsNotRefused(userId, board, swimlaneId, source) {
for (const listId of await swimlaneRefusingListIds(userId, board, swimlaneId)) {
await assertListNotRefused(userId, board, listId, 'write', source);
}
}