mirror of
https://github.com/wekan/wekan.git
synced 2026-11-26 20:45:07 -05:00
GET /api/user and the attachmentMigrationStatuses publication found the caller's boards with a dotted 'members.userId', which also matches boards the caller was removed from, so a removed member kept seeing those board ids (and the publication looked for public boards by a field that does not exist). Both match active memberships now, and boards readable without membership by the shared rule. POST /api/boards/:boardId/copy hand-wrote its admin check without isActive, so a removed former admin could still copy the board; it uses Authentication.checkBoardAdmin. Negative tests fail on any REST handler or publication that finds the caller's boards by a dotted members.userId, or that hand-writes the admin check. Thanks to xet7 !
58 lines
3.3 KiB
JavaScript
58 lines
3.3 KiB
JavaScript
'use strict';
|
|
// Hall of Fame regression coverage: ManageBoardBleed.
|
|
const { test } = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
const read = name => fs.readFileSync(path.join(__dirname, '..', name), 'utf8');
|
|
test('actual board-admin guard denies normal members and accepts board/site admins', async () => {
|
|
const text = read('server/authentication.js');
|
|
const at = text.indexOf(' async checkBoardAdmin(');
|
|
const end = text.indexOf('\n },', at);
|
|
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
|
|
const run = new AsyncFunction('userId', 'boardId', 'Authentication', 'ReactiveCache', 'require', text.slice(text.indexOf('\n', at) + 1, end));
|
|
for (const [isAdmin, siteAdmin] of [[false, false], [true, false], [false, true]]) {
|
|
const logs = [];
|
|
const call = run('u', 'b', {
|
|
checkLoggedIn() {}, checkBoardExists() {},
|
|
async checkAdminOrCondition(id, allowed) { if (!allowed && !siteAdmin) throw Object.assign(Error('Forbidden'), { statusCode: 403 }); },
|
|
}, { getBoard: async () => ({ members: [{ userId: 'u', isActive: true, isAdmin }] }) },
|
|
() => ({ record: event => logs.push(event) }));
|
|
if (isAdmin || siteAdmin) await call;
|
|
else await assert.rejects(call, { statusCode: 403 });
|
|
assert.equal(logs.length, isAdmin || siteAdmin ? 0 : 1);
|
|
}
|
|
});
|
|
test('negative inventory: REST board management and all rule mutations require admin', () => {
|
|
for (const file of ['server/models/boards.js', 'server/models/rules.js']) {
|
|
assert.doesNotMatch(read(file), /Authentication\.checkBoardWriteAccess\(/, file);
|
|
}
|
|
const boards = read('server/models/boards.js');
|
|
for (const route of ['title', 'cardSettings']) {
|
|
const at = boards.indexOf(`WebApp.handlers.put('/api/boards/:boardId/${route}'`);
|
|
const body = boards.slice(at, boards.indexOf('\n});', at));
|
|
assert.match(body, /Authentication\.checkBoardAdmin\(/);
|
|
assert.ok(body.indexOf('checkBoardAdmin') < body.indexOf('Boards.direct.updateAsync'));
|
|
}
|
|
assert.equal((read('server/models/rules.js').match(/Authentication\.checkBoardAdmin\(/g) || []).length, 3);
|
|
});
|
|
|
|
// ManageBoardBleed sibling (2026-10-02): POST /api/boards/:boardId/copy had a
|
|
// hand-written admin check without isActive, so a removed former admin could
|
|
// still copy the board. Negative: no REST handler hand-writes the admin check.
|
|
test('board copy uses the shared admin check, and no handler hand-writes one', () => {
|
|
const boards = read('server/models/boards.js');
|
|
const at = boards.indexOf("WebApp.handlers.post('/api/boards/:boardId/copy'");
|
|
const body = boards.slice(at, boards.indexOf('\nWebApp.handlers.', at + 10));
|
|
assert.ok(body.indexOf('Authentication.checkBoardAdmin(req.userId, id)') < body.indexOf('copy.copy()'));
|
|
const fs = require('node:fs'), path = require('node:path');
|
|
const root = path.join(__dirname, '..');
|
|
const walk = dir => fs.readdirSync(path.join(root, dir), { withFileTypes: true }).flatMap(e => {
|
|
if (e.name === 'tests' || e.name.startsWith('_build')) return [];
|
|
const rel = `${dir}/${e.name}`;
|
|
return e.isDirectory() ? walk(rel) : (rel.endsWith('.js') ? [rel] : []);
|
|
});
|
|
const offenders = walk('server').filter(f => /members\.some\(e => e\.userId === req\.userId && e\.isAdmin\)/.test(read(f)));
|
|
assert.deepEqual(offenders, []);
|
|
});
|