mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
- server/lib/attachmentApiAccess.js: the size limits and the board write check that the attachment Meteor methods (server/attachmentApi.js) and REST routes (server/routes/attachmentApi.js) each defined, identically - seven functions. tests/assignedbleed reads the write check there and fails if either API defines its own again. - server/lib/contentDisposition.js: the Content-Disposition filename functions of server/routes/universalFileServer.js and legacyAttachments.js. - models/lib/fileStoreStrategy.js: the GridFS, filesystem and cloud strategies had the same interceptDownload. The base class now has it, and still fails closed: a strategy whose getReadStream() gives nothing - the base one gives nothing - answers 404 and never hands the file to Meteor-Files unfiltered. tests/attachmentServeFailsClosed holds any override to the same rules. - models/lib/uploadFileId.js: uploadNameParts() reads the id and name of an upload for both Attachments' and Avatars' namingFunction, which each had the same 25 lines. tests/uploadFileId, which the module's comment named but did not exist, covers it and safeUploadFileId. Thanks to xet7 !
49 lines
3.1 KiB
JavaScript
49 lines
3.1 KiB
JavaScript
'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 guardAt = source.indexOf(' async function isAuthorizedForBoard(');
|
||
const guard = source.slice(guardAt, source.indexOf('\n }\n', guardAt) + 4);
|
||
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);
|
||
});
|