mirror of
https://github.com/wekan/wekan.git
synced 2026-11-24 09:59:47 -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 !
66 lines
3.6 KiB
JavaScript
66 lines
3.6 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { Meteor } from 'meteor/meteor';
|
|
import { Accounts } from 'meteor/accounts-base';
|
|
import { DDP } from 'meteor/ddp';
|
|
import { Random } from 'meteor/random';
|
|
import { CloudSettings, CloudDomains } from '/models/cloudPanel';
|
|
|
|
// CloudPanelBleed (server/cloudPanel.js, tests/cloudPanelGate.test.cjs): the
|
|
// Cloud Panel connects to MongoDB servers it is given, so it exists only
|
|
// where the server has the CLOUD environment variable. These run the real
|
|
// methods and the real login handler of the real server, which `meteor test`
|
|
// starts WITHOUT CLOUD - the case of every ordinary WeKan.
|
|
describe('Cloud Panel without CLOUD (CloudPanelBleed)', function () {
|
|
this.timeout(60000);
|
|
const saved = process.env.CLOUD;
|
|
const admin = Random.id();
|
|
const host = 'cloud-test.example.com';
|
|
const call = (userId, name, ...args) => DDP._CurrentMethodInvocation.withValue(
|
|
{ userId, isSimulation: false, connection: { httpHeaders: { host }, clientAddress: '203.0.113.5' }, setUserId() {}, unblock() {} },
|
|
() => Meteor.server.method_handlers[name].apply({ userId, connection: { httpHeaders: { host }, clientAddress: '203.0.113.5' } }, args));
|
|
|
|
before(async function () {
|
|
if (!Meteor.isAppTest) this.skip();
|
|
delete process.env.CLOUD;
|
|
await Meteor.users.rawCollection().insertOne({ _id: admin, username: `cloud-admin-${admin}`, isAdmin: true, profile: {} });
|
|
// What an earlier version let a site administrator store from the
|
|
// browser: this very host as the Cloud Panel Domain, and themselves.
|
|
await CloudSettings.rawCollection().updateOne({ _id: 'cloud' },
|
|
{ $set: { settings: { domain: host, superAdminUsername: `cloud-admin-${admin}` } } }, { upsert: true });
|
|
await CloudDomains.rawCollection().insertOne({ _id: `d-${admin}`, domain: `internal-${admin.toLowerCase()}.example.com`, mode: 'own',
|
|
upstream: 'x:1', database: { host: '127.0.0.1', port: 9, database: 'admin' } });
|
|
});
|
|
|
|
after(async function () {
|
|
if (!Meteor.isAppTest) return;
|
|
if (saved === undefined) delete process.env.CLOUD; else process.env.CLOUD = saved;
|
|
await Meteor.users.rawCollection().deleteOne({ _id: admin });
|
|
await CloudSettings.rawCollection().deleteOne({ _id: 'cloud' });
|
|
await CloudDomains.rawCollection().deleteOne({ _id: `d-${admin}` });
|
|
});
|
|
|
|
it('answers that there is no panel, whatever the database says', async function () {
|
|
const who = await call(admin, 'cloudPanelWhoAmI');
|
|
assert.equal(who.enabled, false);
|
|
assert.equal(who.isCloudAdmin, false);
|
|
});
|
|
|
|
it('negative: refuses every other method to a site administrator', async function () {
|
|
const names = Object.keys(Meteor.server.method_handlers).filter(n => n.startsWith('cloudPanel') && n !== 'cloudPanelWhoAmI');
|
|
assert.ok(names.includes('cloudPanelTestDatabase') && names.includes('cloudPanelSetSettings'));
|
|
for (const name of names) {
|
|
// eslint-disable-next-line no-await-in-loop
|
|
await assert.rejects(Promise.resolve().then(() => call(admin, name, `d-${admin}`, {}, {})), /not-authorized|not do that/, name);
|
|
}
|
|
});
|
|
|
|
it('negative: the customer login stays out of every password login', async function () {
|
|
const handlers = Accounts._loginHandlers.filter(h => h.name === 'password');
|
|
assert.ok(handlers.length >= 2, 'registered beside accounts-password\'s own');
|
|
const mine = handlers.find(h => /customerLogin/.test(String(h.handler)) || /cloudCustomer/.test(String(h.handler)));
|
|
if (!mine) this.skip();
|
|
const result = await mine.handler.call({ connection: { httpHeaders: { host } } }, { user: { username: 'anybody' }, password: 'x' });
|
|
assert.equal(result, undefined);
|
|
});
|
|
});
|