mirror of
https://github.com/wekan/wekan.git
synced 2026-11-25 04:49:41 -05:00
AssignedBleed follow-up, GHSA-3cgr-47wm-9cc9. An assigned-only member
(isNormalAssignedOnly, isCommentAssignedOnly, isReadAssignedOnly) sees only
the cards assigned to them. 1a218ead02 applied that to the attachment API,
but six other paths asked only for board membership, which such a member
has:
- the /cdn/storage/attachments and /cfs/files/attachments downloads
(universalFileServer isAuthorizedForBoard) served any card's file;
- Attachments.protected, ostrio:files' own download check, likewise;
- the legacy /cfs/files/attachments route likewise;
- searchAttachmentDocumentText matched the extracted text of every card's
PDF/DOCX/XLSX/PPTX on the board and returned snippets with their
attachment and card ids - no id needed, and it supplied the ids for the
downloads;
- legacyBoardAttachments without a cardId published every legacy
attachment record of the board;
- linkedListCards published every card of the source list.
The downloads now also ask mayReadBoardAttachment(), which names the
refusing path in Admin Panel -> Problems (authz.assigned, medium: never
disables). The document search and the legacy publication are narrowed to
the member's cards (assignedOnlyCardIds); asking the publication for a card
not assigned to them is refused and recorded, as card details always pass
the open card. Linked-list cards take the source board's
assignedOnlyCardScope; searching and viewing a linked list are ordinary
use, so those are not recorded.
The board's own files - background (sidebar or API upload) and map image -
carry no card and are part of the board every member sees; they stay
readable, where the attachment API refused them to an assigned-only
member. Any other card-less file is still refused.
tests/assignedOnlyReads.test.cjs pins each path, the board-file rule and
the refusal source, and fails when any file in server/ or models/ that
serves attachment or document data lacks the rule without a stated
exemption. The Playwright spec checks both downloads refuse the hidden
card's file but not the member's own, that the search finds only the
member's card, and that the owner is unaffected. Four source guards that
pinned the old lines now pin the new ones.
Thanks to crypto-nidh and xet7 !
59 lines
2.7 KiB
JavaScript
59 lines
2.7 KiB
JavaScript
import { ReactiveCache } from '/imports/reactiveCache';
|
|
|
|
const { isAssignedOnlyMember } = 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;
|
|
}
|