mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -05:00
Fix InactiveBleed across REST, attachment and export authentication, header login, LDAP token issuance and People account controls. Apply administrator-created account flags before insertion and guard token creation atomically. Thanks to esbrito81 and xet7 !
38 lines
2.2 KiB
JavaScript
38 lines
2.2 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 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),
|
||
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('public attachments remain readable without credentials', async () => {
|
||
assert.equal(await policy(null)({}, { isVisibleBy: () => true }), true);
|
||
});
|