mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 18:10:06 -05:00
CloudPanelBleed. Any site administrator of any WeKan could set the Cloud Panel Domain and its SuperAdmin in Admin Panel / People / Cloud and then make the server connect to any MongoDB server with credentials of their choosing - Test connection and Import build a MongoClient from the domain's database settings. A customer is the administrator of their own WeKan container, so a customer could reach MongoDB servers on the internal network. The Cloud Panel now exists only where the server has CLOUD=<its domain> (models/lib/cloudPanel.js cloudDomainFromEnv). The domain is never read from the database, the browser or the REST API; the People / Cloud pane is gone and cloudPanelGetSettings / cloudPanelSetSettings always refuse. Every cloudPanel* method except cloudPanelWhoAmI passes the CLOUD gate before anything else, its argument checks included, and the one MongoClient built from data that is not the environment (withSource) has the gate in its own body. A refusal is recorded in Admin Panel / Problems under the new keys authz.cloud-panel-off, authz.cloud-panel-access and authn.cloud-admin-address (bleed CloudPanelBleed; none disables an account). - Cloud Admins: on the CLOUD container its site administrators - the first registered user is one - not disabled, never a customer's account. They have Admin Panel / Cloud (/admin/cloud/<pane>, a tab shown only for a Cloud Admin at the CLOUD address): Domains, Invoices, Tickets, Chat, Cloudflare, Caddy, Allowed addresses. /cloud stays the customers' panel. - Customer login: a password login handler, ahead of accounts-password's and after the timing normalization, only at the CLOUD address, only for a name exactly one domain with its own database lists, never for a name an account of the panel's own has. The password is checked against that customer's own database hash with Accounts._checkPasswordAsync, under an id no local account has; a disabled or password-less account there is refused, and so is a wrong 2FA code. On success a local non-admin account without a password, services.cloudCustomer, which sees exactly its own domain: info, invoices, tickets and chat. - Support boards: one WeKan board per domain, "Support: <domain>", lists Open / In progress / Done for tickets and Chat with one card whose comments are the support chat (Board View / Chat shows them as a chat). Cloud Admins are board admins, customers Comment only: they read and comment but cannot create, edit, move, archive or delete a card nor manage the board; the panel adds their tickets into Open. The earlier cloudChatMessages are moved once into the chat card; imported Rocket.Chat and SandChat conversations go there too. - Allowed addresses: IPv4, IPv6 and CIDR ranges (models/lib/cloudAddresses.js). When set, a Cloud Admin login (resume included) from elsewhere is refused and recorded, and so is a Cloud Admin method. A list without the saver's own address is refused; CLOUD_ADMIN_ANY_ADDRESS=true sets it aside for a locked-out operator. Tests: tests/cloudPanel.test.cjs, tests/cloudAddresses.test.cjs, tests/cloudPanelAccess.test.cjs (the real methods and login handler without and with CLOUD), tests/cloudPanelGate.test.cjs (the MongoClient source scan), server/lib/tests/cloudPanel.security.tests.js and tests/playwright/specs/cloud-panel.e2e.js (negative without CLOUD; the positive part runs with CLOUD=localhost WEKAN_TEST_CLOUD=true). The guards that pin board inserts, comment inserts, card-reading paths, copy/move methods, the Admin Panel tabs and method areas list the panel's support board and its methods, with the reason. Thanks to xet7 !
146 lines
8.5 KiB
JavaScript
146 lines
8.5 KiB
JavaScript
'use strict';
|
|
|
|
// CloudPanelBleed (2026-11-22): the Cloud Panel connects to MongoDB servers
|
|
// with credentials it is given, and until now any site administrator of any
|
|
// WeKan could switch it on from the browser - Admin Panel / People / Cloud -
|
|
// and make the server connect to MongoDB servers on its internal network. A
|
|
// customer is the administrator of their own WeKan container.
|
|
//
|
|
// The fix is a gate: the CLOUD environment variable. These guards read the
|
|
// source, so the fault cannot come back somewhere else:
|
|
// * the only MongoClient built from data that is not the server's own
|
|
// environment is the Cloud Panel's, and it is behind the CLOUD gate in
|
|
// the very function that builds it;
|
|
// * nothing reads the domain or SuperAdmin the browser used to set;
|
|
// * the REST API at the CLOUD address refuses requests without a login,
|
|
// in front of every route.
|
|
// The behaviour itself is in tests/cloudPanelAccess.test.cjs (every method
|
|
// refused without CLOUD) and tests/cloudPanel.test.cjs (the pure gate).
|
|
// Run: node tests/cloudPanelGate.test.cjs
|
|
|
|
const assert = require('node:assert/strict');
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
const ROOT = path.join(__dirname, '..');
|
|
const read = rel => fs.readFileSync(path.join(ROOT, rel), 'utf8');
|
|
|
|
let passed = 0;
|
|
function test(name, fn) { fn(); passed += 1; console.log(' ok -', name); }
|
|
|
|
// Every source file of the running application - what a request, a method
|
|
// or a page can reach: not the tests, not dependencies, not the bundler's
|
|
// second copy of everything in _build/ (CLAUDE.md), and not the operator's
|
|
// command-line tools of snap-src/bin and releases/, which run in a shell
|
|
// with the arguments the operator types.
|
|
const APP_DIRS = ['server', 'models', 'imports', 'client', 'config', 'packages'];
|
|
const SKIP = new Set(['node_modules', '_build', '.build', '.tools', '.git', '.meteor', 'tests', '.npm']);
|
|
function sources(dir = null, out = []) {
|
|
if (dir === null) {
|
|
for (const top of APP_DIRS) sources(path.join(ROOT, top), out);
|
|
return out;
|
|
}
|
|
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
if (SKIP.has(entry.name) || entry.name.startsWith('_build')) continue;
|
|
const full = path.join(dir, entry.name);
|
|
if (entry.isDirectory()) sources(full, out);
|
|
else if (/\.(c|m)?js$/.test(entry.name)) out.push(path.relative(ROOT, full));
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// A function's body, from its declaration to the closing brace at column 0.
|
|
function functionBody(src, signature) {
|
|
const at = src.indexOf(signature);
|
|
assert.notEqual(at, -1, `no ${signature}`);
|
|
const end = src.indexOf('\n}\n', at);
|
|
return src.slice(at, end + 2);
|
|
}
|
|
|
|
const BUILDS_A_CLIENT = /new\s+MongoClient\s*\(|MongoClient\.connect\s*\(/;
|
|
|
|
test('the only MongoClient built from data that is not the server\'s own environment is the Cloud Panel\'s', () => {
|
|
const found = sources().filter(rel => !/[\\/]tests?[\\/]/.test(rel) && BUILDS_A_CLIENT.test(read(rel)));
|
|
assert.deepEqual(found.sort(), ['server/cloudPanel.js', 'server/methods/migrateTextDatabase.js', 'server/models/attachmentStorageSettings.js'],
|
|
'a new MongoClient anywhere else must be judged here: where does its address come from?');
|
|
// Admin Panel / Attachments compacts the secondaries of the replica set
|
|
// WeKan already runs on: their address is MONGO_URL's.
|
|
const compact = read('server/models/attachmentStorageSettings.js');
|
|
assert.match(compact, /buildDirectNodeUrl\(process\.env\.MONGO_URL, secondary\.name\)/);
|
|
assert.match(compact, /&& process\.env\.MONGO_URL\)/);
|
|
// The text database migration: to the URL the environment names, or the
|
|
// fixed local default - never one the browser sends.
|
|
const migrate = read('server/methods/migrateTextDatabase.js');
|
|
assert.match(functionBody(migrate, 'function targetUrlFor('), /process\.env\.WEKAN_FERRETDB_URL[\s\S]*process\.env\.WEKAN_MONGODB_URL/);
|
|
assert.match(migrate, /const targetUrl = targetUrlFor\(direction\);[\s\S]*MongoClient\.connect\(targetUrl\)/);
|
|
});
|
|
|
|
test('...and it is behind the CLOUD gate in the very function that builds it', () => {
|
|
const src = read('server/cloudPanel.js');
|
|
assert.equal((src.match(new RegExp(BUILDS_A_CLIENT.source, 'g')) || []).length, 1, 'one place');
|
|
const withSource = functionBody(src, 'async function withSource(');
|
|
assert.match(withSource, BUILDS_A_CLIENT, 'in withSource');
|
|
const gate = withSource.indexOf('requireCloud(');
|
|
assert.ok(gate !== -1 && gate < withSource.search(BUILDS_A_CLIENT), 'the gate comes first, whoever calls it');
|
|
// The gate is the environment, read on every call - nothing stored.
|
|
assert.match(functionBody(src, 'function cloudDomainNow('), /return C\.cloudDomainFromEnv\(process\.env\);/);
|
|
const requireCloud = functionBody(src, 'function requireCloud(');
|
|
assert.match(requireCloud, /cloudDomainNow\(\)/);
|
|
assert.match(requireCloud, /recordRefusal\('authz\.cloud-panel-off'/, 'an attempt is recorded in Admin Panel / Problems');
|
|
assert.match(requireCloud, /denied\(\)/);
|
|
assert.match(functionBody(src, 'function recordRefusal('), /try \{[\s\S]*securityLog[\s\S]*\} catch \(e\) \{ \/\* logging must never break the guard \*\/ \}/);
|
|
// Every method but the who-am-I passes the gate before anything else it
|
|
// does, its argument checks included.
|
|
assert.match(src, /for \(const name of Object\.keys\(METHODS\)\) \{\n if \(name === 'cloudPanelWhoAmI'\) continue;[\s\S]*?requireCloud\(`method:\$\{name\}`\);\n return method\.apply\(this, args\);[\s\S]*?\}\nMeteor\.methods\(METHODS\);/);
|
|
// Every way into a customer's database starts at the gate too.
|
|
for (const sig of ['async function onPanel(', 'async function ensureSupportBoard(']) {
|
|
assert.match(functionBody(src, sig), /requireCloud\(/, sig);
|
|
}
|
|
assert.match(functionBody(src, 'async function customerLogin('), /const cloudDomain = cloudDomainNow\(\);\n if \(!cloudDomain \|\|/);
|
|
});
|
|
|
|
test('negative: nothing reads the domain or SuperAdmin the browser used to set', () => {
|
|
for (const rel of sources()) {
|
|
const code = read(rel).replace(/\/\/.*$/gm, '').replace(/\/\*[\s\S]*?\*\//g, '');
|
|
assert.doesNotMatch(code, /superAdminUsername/, `${rel}: the SuperAdmin setting is gone`);
|
|
assert.doesNotMatch(code, /\.settings\.domain\b|all\.settings\b/, `${rel}: the stored Cloud Panel Domain is read by nothing`);
|
|
}
|
|
const client = sources().filter(rel => rel.startsWith('client/') || rel.startsWith('config/'));
|
|
for (const rel of client) {
|
|
assert.doesNotMatch(read(rel), /cloudPanel(Set|Get)Settings/, `${rel}: no page sets it`);
|
|
}
|
|
assert.doesNotMatch(read('client/components/cloud/cloudPanel.jade'), /cloudPanelSettings|superadmin/i);
|
|
assert.doesNotMatch(read('client/components/settings/peopleBody.js'), /'cloud-setting'/, 'Admin Panel / People / Cloud is gone');
|
|
const { ADMIN_PAGES } = require('../models/lib/adminUrls.js');
|
|
assert.equal(ADMIN_PAGES.people.panes.cloud, undefined);
|
|
});
|
|
|
|
test('the REST API at the CLOUD address: refused without a login, in front of every route', () => {
|
|
const mw = read('server/apiMiddleware.js');
|
|
const gate = mw.indexOf('function cloudHostRestGate(');
|
|
assert.ok(gate > mw.indexOf('function authenticateByToken('), 'after the token is read, so a signed-in export still works');
|
|
assert.ok(gate < mw.indexOf("require('/server/lib/apiUsageLog')"), 'before the usage counting and every route');
|
|
const body = mw.slice(gate, mw.indexOf('\n});', gate));
|
|
assert.match(body, /cloudDomainFromEnv\(process\.env\)/);
|
|
assert.match(body, /if \(!cloudDomain\) return next\(\);/, 'negative: a WeKan without CLOUD is unchanged');
|
|
assert.match(body, /key: 'authn\.cloud-rest-off', action: 'blocked'/);
|
|
const imports = read('server/imports.js');
|
|
assert.ok(imports.indexOf("import '/server/apiMiddleware';") < imports.indexOf("import '/server/apiAuthRoutes';"),
|
|
'the middleware is registered before POST /users/login and /users/register');
|
|
});
|
|
|
|
test('every refusal has its key, and none disables an account', () => {
|
|
const { CATALOG } = require('../models/lib/securityCategories.js');
|
|
for (const key of ['authz.cloud-panel-off', 'authz.cloud-panel-access', 'authn.cloud-admin-address', 'authn.cloud-rest-off']) {
|
|
assert.ok(CATALOG[key], key);
|
|
assert.equal(CATALOG[key].bleed, 'CloudPanelBleed', key);
|
|
assert.equal(CATALOG[key].blocksAccount, false, `${key}: refused, and recorded, but nobody's account is disabled for it`);
|
|
}
|
|
const src = read('server/cloudPanel.js');
|
|
for (const key of ['authz.cloud-panel-off', 'authz.cloud-panel-access', 'authn.cloud-admin-address']) {
|
|
assert.ok(src.includes(`'${key}'`), `${key} is recorded`);
|
|
}
|
|
});
|
|
|
|
console.log(`\ncloudPanelGate: ${passed} tests passed`);
|