Files
wekan/tests/boardPrivateOnlyMethod.test.cjs
T
Lauri Ojansivu 5c1f6088f4 Fix CreateBleed: "Only admins can create boards" holds on every path.
GHSA-qcfm-2g4w-wqcc. Admin Panel / Settings / Visibility / "Only admins
can create boards" (#4475) was checked only inside
createBoardWithInitialSwimlanes, the Add Board form. A non-admin still
created working boards by a client Boards.insert (Boards.allow.insert
approves any signed-in user), POST /api/boards and both board import
routes, as reported, and also by importBoard, cloneBoard, copyBoard,
POST /api/boards/:boardId/copy and createBoardFromCard.

One decision (models/lib/boardCreationPolicy.js) and one guard
(server/lib/boardCreationGuard.js) are asked by every one of those paths
before they write, and by a new Boards.deny insert rule. A board template
stays every member's own; boards WeKan makes itself (a Templates container,
a board's subtasks board) are not created by the user. A REST refusal is
403. A refusal is recorded in Admin Panel / Problems as CreateBleed
(authz.board-creation, low, CWE-863, blocks no account), and Duplicate and
"Create board from card" are hidden like Add Board, so only a client
bypassing the interface reaches it.

tests/createBleed.test.cjs drives the decision, the guard and the real deny
rule against the reporter's console insert, and fails if any path that
creates a board for a user does not ask the guard, or if anything else
reads the setting. tests/playwright/specs/createbleed-board-creation-admin-only.e2e.js
replays the report against a running server. The guards that pinned the
old inline check now pin the shared one.

Thanks to tsurutanmen and xet7 !
2026-11-07 00:51:53 +02:00

54 lines
4.2 KiB
JavaScript

'use strict';
// Hall of Fame regression coverage: VisibilityBleed.
const assert = require('node:assert/strict');
const fs = require('node:fs');
const source = fs.readFileSync(require('node:path').join(__dirname, '../server/models/boards.js'), 'utf8');
const start = source.indexOf(' async createBoardWithInitialSwimlanes(payload) {');
const end = source.indexOf(' const boardId = await Boards.insertAsync({', start);
assert.ok(start >= 0 && end > start);
const prefix = source.slice(start, end).replace(' async createBoardWithInitialSwimlanes(payload) {', '');
const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
// #3249: "private boards only" refuses 'instance' boards as well as public
// ones; the server code asks isOpenPermission() for both.
const { isOpenPermission } = require('../models/lib/boardPermission.js');
// assertMayCreateBoard is CreateBleed's guard (tests/createBleed.test.cjs);
// here creating is allowed, so the private-only policy is seen alone.
const run = new AsyncFunction('payload', 'check', 'Match', 'Meteor', 'TableVisibilityModeSettings', 'ReactiveCache', 'require', 'isOpenPermission', 'assertMayCreateBoard', prefix + '\nreturn permission;');
(async () => {
for (const privateOnly of [false, true]) {
for (const requested of ['private', 'public', 'instance']) {
const logs = [];
const settings = { findOneAsync: async key => ({ booleanValue: key === 'tableVisibilityMode-allowPrivateOnly' && privateOnly }) };
const result = await run.call({ userId: 'creator' }, { title: 'T', slug: 't', permission: requested }, () => {}, { ObjectIncluding: x => x, Maybe: x => x }, {}, settings, {}, () => ({ record: x => logs.push(x) }), isOpenPermission, async () => {});
assert.equal(result, privateOnly ? 'private' : requested);
assert.equal(logs.length, privateOnly && requested !== 'private' ? 1 : 0, 'only blocked public or instance requests are logged');
}
}
const cards = fs.readFileSync(require('node:path').join(__dirname, '../server/models/cards.js'), 'utf8');
const at = cards.indexOf(" const privateOnly = await TableVisibilityModeSettings.findOneAsync(");
assert.ok(at > 0);
const conversion = new AsyncFunction('sourceBoard', 'TableVisibilityModeSettings', 'require', 'isOpenPermission', cards.slice(at, cards.indexOf(' const boardId = await Boards.insertAsync({', at)) + '\nreturn permission;');
for (const enabled of [false, true]) {
const settings = { findOneAsync: async () => ({ booleanValue: enabled }) };
for (const inherited of ['public', 'instance']) {
assert.equal(await conversion({ permission: inherited }, settings, () => ({ record() { throw Error('logger unavailable'); } }), isOpenPermission),
enabled ? 'private' : inherited, 'conversion policy survives logging failure');
}
assert.equal(await conversion({ permission: 'something' }, settings, () => ({ record() {} }), isOpenPermission), 'private',
'an unknown source permission falls back to private');
}
assert.ok(!/permission:\s*sourceBoard\.permission/.test(cards), 'negative: conversion no longer copies visibility without policy');
assert.ok(source.indexOf("'tableVisibilityMode-allowPrivateOnly'", start) < end, 'negative: method policy runs before insert');
const hookAt = source.indexOf('Boards.before.insert(async (userId, doc) => {');
const hookEnd = source.indexOf('\n});', hookAt);
const hook = new AsyncFunction('userId', 'doc', 'TableVisibilityModeSettings', 'ReactiveCache', 'require', 'isOpenPermission', source.slice(source.indexOf('\n', hookAt) + 1, hookEnd));
for (const enabled of [false, true]) {
for (const permission of ['public', 'instance']) {
const doc = { permission };
await hook('u', doc, { findOneAsync: async () => ({ booleanValue: enabled }) }, { getBoard: async () => null }, () => ({ record() { throw Error('logger unavailable'); } }), isOpenPermission);
assert.equal(doc.permission, enabled ? 'private' : permission, 'shared copy/import/helper insert policy survives logger failure');
}
}
console.log('boardPrivateOnlyMethod: server decision preserves private-only policy');
})().catch(error => { console.error(error); process.exitCode = 1; });