Files
wekan/server/lib/tests/adminPanelAddresses.tests.js
T
Lauri Ojansivu 7f12264542 Admin Panel allowed addresses: from any other address the Admin Panel and the admin REST API refuse.
Admin Panel / Settings / Privacy and security / Allowed addresses is a list of
IPv4 and IPv6 addresses and CIDR ranges. Empty, the default, is any address.
When it is set, a site administrator at any other address reads as a member:
every admin method, publication, allow rule and admin REST endpoint refuses
them, the Admin Panel's tabs say why, and their boards keep working. Members
are not affected.

It is enforced where every admin check reads: the caller's user document,
through Meteor.users.findOneAsync (Meteor.userAsync, ReactiveCache.getUser
and the allow rules all end there). For the caller of the running DDP method,
publication or HTTP request, their own document reads isAdmin false, and a
query that asks about isAdmin answers as it would for a member. Signing in
reads the stored flag, because OIDC and LDAP write it back.

The address and range rules are the Cloud Panel's (models/lib/cloudAddresses.js),
and the address is resolved with HTTP_FORWARDED_COUNT like every other guard.
A list without the saver's own address is refused, in the page before saving
and on the server, and a browser write of the field is denied. The server's
ADMIN_PANEL_ALLOWED_IP_ADDRESSES wins over the list, and "any" lifts it: the
way back in. It is listed on every platform.

A refused admin action from another address is one row in Admin Panel /
Problems (authz.admin-panel-address), once per call, without disabling the
account.

Translations of the three new strings into every locale were written
directly; the rarer languages (for example Cherokee, Inuktitut, Tigre,
Wolaytta, Nahuatl, Veps, Klingon) are low confidence.

Thanks to xet7 !
2026-11-22 20:28:30 +02:00

84 lines
4.7 KiB
JavaScript

import assert from 'node:assert/strict';
import { Meteor } from 'meteor/meteor';
import { DDP } from 'meteor/ddp';
import { Random } from 'meteor/random';
// Admin Panel / Settings / Privacy and security / Allowed addresses
// (server/adminPanelAddresses.js, tests/adminPanelAddresses.test.cjs): the
// real user read of the real server, inside a method call from an address the
// list has and from one it does not. The list comes from the environment, so
// no setting of the test database is touched.
describe('Admin Panel allowed addresses', function () {
this.timeout(60000);
const saved = process.env.ADMIN_PANEL_ALLOWED_IP_ADDRESSES;
const admin = Random.id();
const member = Random.id();
const connectionAt = clientAddress => ({ httpHeaders: {}, clientAddress, id: Random.id() });
const as = (userId, clientAddress, name, fn) => {
const connection = connectionAt(clientAddress);
return DDP._CurrentMethodInvocation.withValue(
{ userId, name, isSimulation: false, connection, setUserId() {}, unblock() {} }, () => fn({ userId, connection }));
};
const call = (userId, clientAddress, name, ...args) => as(userId, clientAddress, name,
self => Meteor.server.method_handlers[name].apply(self, args));
before(async function () {
if (!Meteor.isAppTest) this.skip();
process.env.ADMIN_PANEL_ALLOWED_IP_ADDRESSES = '192.0.2.0/24, 2001:db8::/32';
await Meteor.users.rawCollection().insertOne({ _id: admin, username: `apa-admin-${admin}`, isAdmin: true, profile: {} });
await Meteor.users.rawCollection().insertOne({ _id: member, username: `apa-member-${member}`, profile: {} });
});
after(async function () {
if (!Meteor.isAppTest) return;
if (saved === undefined) delete process.env.ADMIN_PANEL_ALLOWED_IP_ADDRESSES; else process.env.ADMIN_PANEL_ALLOWED_IP_ADDRESSES = saved;
await Meteor.users.rawCollection().deleteMany({ _id: { $in: [admin, member] } });
});
it('an administrator at an allowed address is an administrator', async function () {
for (const at of ['192.0.2.7', '::ffff:192.0.2.7', '2001:db8::9']) {
// eslint-disable-next-line no-await-in-loop
const user = await as(admin, at, 'x', () => Meteor.users.findOneAsync(admin));
assert.equal(user.isAdmin, true, at);
// eslint-disable-next-line no-await-in-loop
assert.ok(await as(admin, at, 'x', () => Meteor.users.findOneAsync({ _id: admin, isAdmin: true })), at);
}
});
it('negative: from any other address the same administrator reads as a member', async function () {
const user = await as(admin, '203.0.113.9', 'x', () => Meteor.users.findOneAsync(admin));
assert.equal(user.isAdmin, false);
assert.equal(user.username, `apa-admin-${admin}`, 'still found: their boards work');
assert.equal(await as(admin, '203.0.113.9', 'x', () => Meteor.users.findOneAsync({ _id: admin, isAdmin: true })), null);
const stored = await Meteor.users.findOneAsync(admin);
assert.equal(stored.isAdmin, true, 'outside any caller the stored flag is read as it is');
});
it('negative: the admin methods refuse from outside the list, and the lockout is refused inside it', async function () {
await assert.rejects(Promise.resolve().then(() => call(admin, '203.0.113.9', 'getAdminPanelAllowedAddresses')), /not-authorized/);
await assert.rejects(Promise.resolve().then(() => call(admin, '203.0.113.9', 'saveAdminPanelAllowedAddresses', '203.0.113.0/24')), /not-authorized/);
const config = await call(admin, '192.0.2.7', 'getAdminPanelAllowedAddresses');
assert.equal(config.source, 'env');
assert.equal(config.yourAddress, '192.0.2.7');
await assert.rejects(Promise.resolve().then(() => call(admin, '192.0.2.7', 'saveAdminPanelAllowedAddresses', '198.51.100.0/24')), /lock you out/);
assert.deepEqual(await call(admin, '203.0.113.9', 'adminPanelAddressStatus'), { refused: true, yourAddress: '203.0.113.9' });
assert.deepEqual(await call(admin, '192.0.2.7', 'adminPanelAddressStatus'), { refused: false });
});
it('negative: a member is not affected, from anywhere', async function () {
const user = await as(member, '203.0.113.9', 'x', () => Meteor.users.findOneAsync(member));
assert.equal(user.username, `apa-member-${member}`);
assert.deepEqual(await call(member, '203.0.113.9', 'adminPanelAddressStatus'), { refused: false });
});
it('"any" in the environment lifts the restriction', async function () {
process.env.ADMIN_PANEL_ALLOWED_IP_ADDRESSES = 'any';
try {
const user = await as(admin, '203.0.113.9', 'x', () => Meteor.users.findOneAsync(admin));
assert.equal(user.isAdmin, true);
} finally {
process.env.ADMIN_PANEL_ALLOWED_IP_ADDRESSES = '192.0.2.0/24, 2001:db8::/32';
}
});
});