Files
wekan/tests/adminAttachmentRead.test.cjs
T
Lauri Ojansivu 7f3428db8e Keep assigned-only members to their own cards' files on every read path.
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 !
2026-10-15 22:42:14 +03:00

48 lines
3.1 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const assert = require('node:assert/strict');
const fs = require('node:fs');
const vm = require('node:vm');
const { test } = require('node:test');
const source = fs.readFileSync('server/routes/universalFileServer.js', 'utf8');
const resolver = source.slice(source.indexOf(' async function getUserFromToken('), source.indexOf(' /**\n * Authorization helper'));
const guard = source.slice(source.indexOf(' async function isAuthorizedForBoard('), source.indexOf(' /**\n * Helper function to properly encode'));
const board = { isVisibleBy: user => user?._id === 'member' };
function policy(user) {
return vm.runInNewContext(`${resolver}\n${guard}\nisAuthorizedForBoard`, {
require: () => ({ activeUserByToken: async () => user?.loginDisabled ? null : user }),
extractLoginToken: req => req.token,
isSandstormRequest: () => false,
canReadBoard: (id, value) => !!value?.isVisibleBy(id ? { _id: id } : null),
// GHSA-3cgr-47wm-9cc9: membership is no longer the whole answer; the
// assigned-only rule decides per file (tests/assignedOnlyReads.test.cjs).
mayReadBoardAttachment: async (b, userId, attachment) => !(attachment && attachment.hiddenFrom === userId),
process: { env: {} },
});
}
test('Files Report administrator can read another member’s private attachment', async () => {
assert.equal(await policy({ _id: 'admin', isAdmin: true })({ token: 'valid-token-123' }, board), true);
});
test('ordinary private-board access still requires membership', async () => {
for (const [user, expected] of [[{ _id: 'member' }, true], [{ _id: 'member', loginDisabled: true }, false], [{ _id: 'outsider' }, false], [null, false]]) {
assert.equal(await policy(user)({ token: 'valid-token-123' }, board), expected);
}
});
test('missing credentials, disabled admin, non-boolean admin and missing board do not grant access', async () => {
assert.equal(await policy({ _id: 'admin', isAdmin: true })({}, board), false);
assert.equal(await policy({ _id: 'admin', isAdmin: true })({ token: 'short' }, board), false);
for (const user of [{ _id: 'admin', isAdmin: true, loginDisabled: true }, { _id: 'outsider', isAdmin: 'true' }]) {
assert.equal(await policy(user)({ token: 'valid-token-123' }, board), false);
}
assert.equal(await policy({ _id: 'admin', isAdmin: true })({ token: 'valid-token-123' }, null), false);
});
test('GHSA-3cgr-47wm-9cc9: a member is refused a file the assigned-only rule hides from them', async () => {
const hidden = { hiddenFrom: 'member' };
assert.equal(await policy({ _id: 'member' })({ token: 'valid-token-123' }, board, hidden, 'file-server:cdn'), false);
assert.equal(await policy({ _id: 'member' })({ token: 'valid-token-123' }, board, {}, 'file-server:cdn'), true);
// The Files Report administrator is not an assigned-only member (negative).
assert.equal(await policy({ _id: 'admin', isAdmin: true })({ token: 'valid-token-123' }, board, { hiddenFrom: 'admin' }), true);
});
test('public attachments remain readable without credentials', async () => {
assert.equal(await policy(null)({}, { isVisibleBy: () => true }), true);
});