Files
wekan/server/lib/visibleBoardIds.js
T
Lauri Ojansivu 35daaaa279 ParentBleed: one card id bridged a private board into another board's feed.
A card's `parentId` may name a card on ANOTHER board, and setting it was
authorized only against the CHILD board's write ACL - nothing asked whether the
person setting it, or the people subscribed to the child board, were allowed to
see the other board at all.

The board publication walks the whole ancestor chain, because the
'prefix-with-full-path' subtask setting renders a subtask's complete path
(#3453), and it published the complete ancestor card DOCUMENTS to every
subscriber of the child board. So a member who could write on shared board B and
knew a card id on private board A could point a card at it and have A's card -
title, description, custom fields - delivered over DDP to people who are not
members of A (CWE-200, CWE-862).

Closed at both ends, because either alone leaves half the hole open.

The WRITE refuses a parent whose board the actor cannot see. That is one
question, asked in one place (server/lib/visibleBoardIds.js) with the same
selectors the publication and All Boards use - so an ACTIVE org, team or domain
share counts and a revoked one does not. It is enforced on the REST card create,
on the REST card update (the PUT the report used), and on DDP by a deny rule
covering both insert and update, beside the cross-board MOVE deny that
GHSA-gm7v-pc38-53jr added. A parent that does not exist is refused too. Clearing
or omitting a parent is untouched.

The PUBLICATION sends only the ancestors whose board the subscriber may see. The
board being published is its own answer, so a normal same-board subtask path is
unchanged; an ancestor on a board the subscriber cannot see is simply not sent,
and a chain that yields nothing publishes nothing.

This is the shape of the check the linked-card path already made - creating a
linked card requires read access to the source card's board - applied to the
field that did not have it.

tests/crossBoardParentCardLeak.test.cjs pins the filtered cursor, that the
unfiltered publish of every ancestor is gone, that both REST paths validate
before writing, that the deny rule covers insert as well as update, and that
clearing a parent and the pre-existing cross-board move deny still work.

Thanks to Alpastx and xet7 !

Fixes GHSA-jvv9-498p-hxrg.
2026-08-09 02:20:37 +03:00

89 lines
3.2 KiB
JavaScript

import { Meteor } from 'meteor/meteor';
import { ReactiveCache } from '/imports/reactiveCache';
const { boardVisibilitySelectors } = require('/models/lib/boardVisibilitySelectors');
// "Which of these boards may this user see?" — asked with the SAME selectors as
// the All Boards list and the `board` publication, so a board is visible here
// exactly when it is visible there: public, an active membership, or an ACTIVE
// org/team/domain share.
//
// GHSA-jvv9-498p-hxrg: a card's `parentId` could point at a card on ANOTHER
// board, and nothing checked that the person setting it, or the people
// subscribed to the child board, were allowed to see that other board. The
// board publication walks the whole ancestor chain to render a subtask's path
// (#3453) and published the full ancestor card documents to every subscriber of
// the child board — so writing one id into one field bridged a private board's
// cards into another board's DDP feed. Both ends of that now ask this question:
// the write refuses an invisible parent, and the publication refuses to send
// ancestors from a board the subscriber cannot see.
/**
* @param {string} userId
* @param {string[]} boardIds
* @return {Promise<Set<string>>} the subset of boardIds the user may see
*/
export async function visibleBoardIds(userId, boardIds) {
const ids = (Array.isArray(boardIds) ? boardIds : [])
.filter(id => typeof id === 'string' && id);
if (ids.length === 0) {
return new Set();
}
const user = userId ? await ReactiveCache.getUser(userId) : null;
const $or = boardVisibilitySelectors({
userId: user ? userId : null,
orgIds: user && typeof user.orgIds === 'function' ? user.orgIds() : [],
teamIds: user && typeof user.teamIds === 'function' ? user.teamIds() : [],
emailDomains:
user && typeof user.emailDomains === 'function' ? user.emailDomains() : [],
});
// An anonymous caller still sees public boards, so $or is never empty.
const boards = await ReactiveCache.getBoards(
{ _id: { $in: ids }, $or },
{ fields: { _id: 1 } },
);
return new Set((boards || []).map(board => board._id));
}
/**
* @param {string} userId
* @param {string} boardId
* @return {Promise<boolean>}
*/
export async function canUserSeeBoard(userId, boardId) {
if (!boardId) return false;
const visible = await visibleBoardIds(userId, [boardId]);
return visible.has(boardId);
}
/**
* Refuse a `parentId` that names a card on a board this user cannot see.
* Throws so both the DDP mutation and the REST handler stop before writing;
* the REST layer maps `Forbidden`/`NotFound` to 403/404
* (server/lib/apiResponseHelpers.js httpStatusForError).
*
* @param {string} userId the actor
* @param {string} parentId the proposed parent card id
*/
export async function assertParentCardIsVisible(userId, parentId) {
if (!parentId) return;
const parent = await ReactiveCache.getCard(parentId);
if (!parent) {
const error = new Meteor.Error('NotFound', 'Parent card not found');
error.statusCode = 404;
throw error;
}
if (!(await canUserSeeBoard(userId, parent.boardId))) {
const error = new Meteor.Error(
'Forbidden',
'You are not allowed to use a card from that board as a parent.',
);
error.statusCode = 403;
throw error;
}
}