mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
A board admin can refuse a role write access in one list (#4527, roleExceptions). The attachment API's upload, delete, copy and move, over REST and DDP, asked only for board write access and mayWriteCardAttachment, which allows every card to a member who is not assigned-only, so a normal member the list refused still added and removed files on that list's cards. Every attachment write that names a card now also asks mayWriteInCardList with that card, and a move asks both the card it takes the file from and the card it puts it on. The card's own board decides. As for the REST card routes, only a list's refusal counts. A refusal is recorded in Admin Panel -> Problems as ListLockAttachBleed (authz.list-locked-attachment, medium). tests/listLockAttachments.test.cjs runs the guard on the reported case and the negative cases, and fails on any mayWriteCardAttachment call in the tree without the list check beside it; list-lock-attachments.e2e.js replays the writes against a running server. Thanks to Furkan Derse and xet7 !
106 lines
5.4 KiB
JavaScript
106 lines
5.4 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
|
|
const { isAssignedOnlyMember, assignedOnlyAllowsCard } = require('/models/lib/boardCardScope');
|
|
|
|
// An assigned-only member (isReadAssignedOnly, isNormalAssignedOnly,
|
|
// isCommentAssignedOnly) sees only the cards assigned to them, and so only
|
|
// those cards' attachments. The board publication applies that; the attachment
|
|
// API asked only board.hasMember(), so its list endpoints enumerated - and its
|
|
// download and info endpoints served - every attachment on the board.
|
|
|
|
// The ids of the cards of this board assigned to this member, or null when the
|
|
// member is not restricted.
|
|
export async function assignedOnlyCardIds(board, userId) {
|
|
if (!isAssignedOnlyMember(board, userId)) return null;
|
|
const cards = await ReactiveCache.getCards(
|
|
{ boardId: board._id, assignees: userId },
|
|
{ fields: { _id: 1 } },
|
|
);
|
|
return (cards || []).map(card => card._id);
|
|
}
|
|
|
|
// The attachment selector clause for this member, or null when unrestricted.
|
|
export async function assignedOnlyAttachmentScope(board, userId) {
|
|
const ids = await assignedOnlyCardIds(board, userId);
|
|
return ids && { 'meta.cardId': { $in: ids } };
|
|
}
|
|
|
|
// Files of the board itself, not of a card: its background (sidebar or API
|
|
// upload) and its map image. Every member sees them as part of the board.
|
|
// Any other attachment without a card is still refused to an assigned-only
|
|
// member.
|
|
const BOARD_LEVEL_SOURCES = new Set(['board-background', 'api-background', 'board-map']);
|
|
export function isBoardLevelFile(attachment) {
|
|
const meta = (attachment && attachment.meta) || {};
|
|
return !meta.cardId && BOARD_LEVEL_SOURCES.has(meta.source);
|
|
}
|
|
|
|
// May this member read this attachment of this board? A refusal is an
|
|
// attempt - no listing names another card's attachment to this member - so it
|
|
// is recorded under AssignedBleed (medium: never disables). `source` names the
|
|
// path that refused, for Admin Panel -> Problems.
|
|
export async function mayReadBoardAttachment(board, userId, attachment, source = 'attachment-api:read') {
|
|
if (!isAssignedOnlyMember(board, userId)) return true;
|
|
if (isBoardLevelFile(attachment)) return true;
|
|
const cardId = attachment && attachment.meta && attachment.meta.cardId;
|
|
const card = cardId ? await ReactiveCache.getCard(cardId) : null;
|
|
const allowed = !!card && card.boardId === board._id
|
|
&& Array.isArray(card.assignees) && card.assignees.includes(userId);
|
|
if (!allowed) {
|
|
try {
|
|
require('/server/lib/securityLog').record({
|
|
key: 'authz.assigned', action: 'blocked', source, userId,
|
|
detail: 'Assigned-only member asked for an attachment of a card not assigned to them.',
|
|
});
|
|
} catch (e) { /* logging must never break the guard */ }
|
|
}
|
|
return allowed;
|
|
}
|
|
|
|
// May this member WRITE an attachment of this card - add one to it, soft-delete
|
|
// one of it, or copy or move one onto it? Board write access is not enough: an
|
|
// assigned-only member writes only on a card assigned to them, as on every
|
|
// other card path. The REST routes asked only for board write access, so a
|
|
// member whose assignment was removed kept adding and deleting files on that
|
|
// card with the ids they had seen (UnassignedAttachBleed,
|
|
// GHSA-w26g-rc43-q6cm). A board-level file has no card and is not theirs to
|
|
// change either. `source` names the refusing route for Admin Panel -> Problems.
|
|
export function mayWriteCardAttachment(board, userId, card, source) {
|
|
if (!isAssignedOnlyMember(board, userId)) return true;
|
|
const allowed = !!card && card.boardId === board._id && assignedOnlyAllowsCard(board, userId, card);
|
|
if (!allowed) {
|
|
try {
|
|
require('/server/lib/securityLog').record({
|
|
key: 'authz.assigned-attachment-write', action: 'blocked', source, userId,
|
|
detail: 'Assigned-only member tried to change an attachment of a card not assigned to them.',
|
|
});
|
|
} catch (e) { /* logging must never break the guard */ }
|
|
}
|
|
return allowed;
|
|
}
|
|
|
|
// May this user write an attachment of this card, as its LIST sees it? A board
|
|
// admin can refuse a role write access in one list (#4527); the attachment
|
|
// API asked only for board write access and mayWriteCardAttachment above, so
|
|
// a member the list refused still added, deleted, copied and moved files on
|
|
// that list's cards (ListLockAttachBleed, a sibling of ListLockBleed,
|
|
// GHSA-4734-8vrg-8j3w). Every attachment write that names a card asks this
|
|
// too, beside the board and assigned-only checks. As for the REST card
|
|
// routes, only a list's REFUSAL counts: its grant does not open the API to a
|
|
// role the board does not let write. The card's own board decides, whatever
|
|
// board the caller named. A board-level file has no card and no list.
|
|
// `source` names the refusing route for Admin Panel -> Problems.
|
|
export async function mayWriteInCardList(board, userId, card, source) {
|
|
if (!card) return true;
|
|
const { listException } = require('/server/lib/listPermissionGate');
|
|
const cardBoard = board && board._id === card.boardId ? board : await ReactiveCache.getBoard(card.boardId);
|
|
if ((await listException(userId, cardBoard, card.listId, 'write')) !== false) return true;
|
|
try {
|
|
require('/server/lib/securityLog').record({
|
|
key: 'authz.list-locked-attachment', action: 'blocked', source, userId,
|
|
detail: 'An attachment write on a card in a list whose exception refuses the caller\'s role.',
|
|
});
|
|
} catch (e) { /* logging must never break the guard */ }
|
|
return false;
|
|
}
|