Files
wekan/models/lib/boardVisibilitySelectors.js
T
Lauri Ojansivu 08baf7fd1b RevokeBleed: revoking an org, team or domain share did not revoke it.
`isActive: false` is how a board admin REVOKES a share with an organization, a
team or an email domain. The All Boards list honoured it - it matches shares
with `$elemMatch: { ..., isActive: true }` - so a revoked user watched the board
disappear from their list and everything looked correct.

The `board` publication did not. That is the publication that sends the board
document and its lists, swimlanes, cards, comments and attachments, and it
matched shares with a dotted selector instead:

    $or.push({ 'orgs.orgId': { $in: orgsIds } });
    $or.push({ 'teams.teamId': { $in: teamsIds } });
    $or.push({ 'domains.domain': { $in: emailDomains } });

A dotted path matches an element of the array without saying anything about
that element's other fields, so isActive was never consulted. Anyone who still
knew the boardId - a bookmark, a browser tab, a note - could subscribe and
receive the whole private board after their access had been taken away
(CWE-639, CWE-863). A revoke the primary data publication does not honour is
not a revoke.

The rule was written out twice and the two copies disagreed, so it is written
once now: models/lib/boardVisibilitySelectors.js builds the `$or`, both
Boards.userBoards and the `board` publication call it, and every share kind is
matched with `$elemMatch` requiring `isActive: true`. `includePublic: false`
still drops the public clause and only that clause, which is what the search
over all boards needs.

tests/boardShareRevokeBypass.test.cjs pins each share kind's selector shape,
that no clause anywhere matches a share without requiring isActive, that the
three dotted selectors are not produced at all, and that junk in the id lists is
dropped rather than handed to Mongo. tests/searchBoardScope.test.cjs asked its
question of the old array literal; it now asks it of the builder - the
behaviour it protects is unchanged.

Thanks to Alpastx and xet7 !

Fixes GHSA-gwc4-fw7p-gw58.
2026-08-09 02:20:13 +03:00

65 lines
2.5 KiB
JavaScript

// Pure, dependency-free construction of the Mongo `$or` that answers "which
// boards may this user see". No Meteor imports, so it is unit tested directly
// with plain Node (tests/boardVisibilitySelectors.test.cjs).
//
// GHSA-gwc4-fw7p-gw58: this was written out TWICE, and the two copies disagreed.
// Boards.userBoards() - the All Boards list - matched org/team/domain shares
// with `$elemMatch: { ..., isActive: true }`, but the `board` publication (the
// one that sends the board and all its cards) matched them with a dotted
// `'orgs.orgId': { $in: [...] }`, which ignores isActive entirely. isActive is
// the REVOKE switch: setting a share to `isActive: false` made the board vanish
// from All Boards, as it should, while a user who still knew the boardId could
// subscribe to it and receive the whole private board. A revoke that the primary
// data publication does not honour is not a revoke.
//
// So there is one builder now, and both callers use it. A share entry counts
// only while it is active, everywhere.
/**
* @param {object} args
* @param {string} [args.userId] the subscriber; omitted/falsy means anonymous
* @param {string[]} [args.orgIds] organisations the user belongs to
* @param {string[]} [args.teamIds] teams the user belongs to
* @param {string[]} [args.emailDomains] the user's verified email domains (#5850)
* @param {boolean} [args.includePublic=true] include `{ permission: 'public' }`,
* which is not a relationship to the user at all but "anybody may open
* this" - wanted in a board LIST, not in a search over all boards.
* @return {object[]} the `$or` clauses, in a stable order
*/
function boardVisibilitySelectors({
userId,
orgIds = [],
teamIds = [],
emailDomains = [],
includePublic = true,
} = {}) {
const selectors = [];
if (includePublic) {
selectors.push({ permission: 'public' });
}
if (!userId) {
return selectors;
}
const clean = (values) =>
Array.isArray(values) ? values.filter((v) => typeof v === 'string' && v) : [];
selectors.push({ members: { $elemMatch: { userId, isActive: true } } });
selectors.push({
orgs: { $elemMatch: { orgId: { $in: clean(orgIds) }, isActive: true } },
});
selectors.push({
teams: { $elemMatch: { teamId: { $in: clean(teamIds) }, isActive: true } },
});
// #5850: domain-based board sharing — board shared with the user's email domain.
selectors.push({
domains: { $elemMatch: { domain: { $in: clean(emailDomains) }, isActive: true } },
});
return selectors;
}
module.exports = { boardVisibilitySelectors };