fix(staff): check every moderator panel action, end panel sessions with the rest

From the 18 October security audit (S-9, S-10).

- the moderator panel only refused a role the actions in its permission
  map. hardware bans and lifting them were missing from it, and answering
  ban appeals (which lifts the ban, the address's too), name requests,
  paintings and reports were checked for player.view alone, so a Helper
  could do all of them. each now needs its own permission (address.ban,
  player.ban, player.names, items.approve, player.warn), with the rank
  check the other actions have, and an action missing from the map is
  refused. the page hides what the role cannot do.
- a new password, "Sign out everywhere", locking the account, turning 2FA
  off or deleting the account now also ends its moderator panel sessions,
  as the admin panel's reset already did, so a stolen panel session does
  not outlive them.
- test/staff.js covers both, and fails without either fix.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
SnipzilandClaude Opus 5.5 committed 2026-10-18 13:17:58 -04:00
1 parent a359371a48
commit 1e365b95c5
6 files changed
+181 -33

No files matched your search

+74 -4
View File
@@ -153,13 +153,16 @@ const maskedAddress = ban => ({
const wholeNumber = (value, min, max) => (Number.isInteger(value) && value >= min && value <= max ? value : null);
// the permission (lib/roles.js) each action needs.
// the permission (lib/roles.js) each action needs. an action that is not
// here is refused (act), so that a new one cannot go unchecked.
const ACTION_PERMISSIONS = {
ban: "player.ban", banReason: "player.ban", unban: "player.ban",
silence: "chat.silence", unsilence: "chat.silence",
kick: "player.kick", message: "player.warn", warn: "player.warn", unwarn: "player.warn",
rejectName: "player.names", acceptName: "player.names", clearBio: "player.names",
clearWallPosts: "player.names", banAddress: "address.ban",
// a computer's ban, as an address's, keeps out everyone who uses it
banDevices: "address.ban", unbanDevices: "address.ban",
summon: "player.summon", goto: "player.goto",
note: "player.view", deleteNote: "player.view",
};
@@ -180,8 +183,11 @@ const act = (mod, target, body) => {
if (!roles.outranks(mod, target)) {
return {error: "Staff of your rank or above are for someone higher up to deal with."};
}
const permission = ACTION_PERMISSIONS[body.action];
if (permission && !roles.can(mod, permission)) {
const permission = Object.hasOwn(ACTION_PERMISSIONS, body.action) ? ACTION_PERMISSIONS[body.action] : null;
if (!permission) {
return {error: "Unknown action."};
}
if (!roles.can(mod, permission)) {
return {error: "Your role cannot do that."};
}
switch (body.action) {
@@ -421,6 +427,23 @@ const handle = async (req, res, url, from, web) => {
}
reply(result.ok ? 200 : 400, result.ok ? {ok: result.ok} : {error: result.error});
};
// a route's permission (lib/roles.js), as act() checks an action's: a
// role without it is refused here, whatever its page shows.
const may = permission => {
if (roles.can(mod, permission)) {
return true;
}
reply(403, {error: "Your role cannot do that."});
return false;
};
// why the moderator may not act on `account`, as act() refuses: not on
// themselves, nor on staff of their rank or above. null when they may.
const refusalFor = account => {
if (!account || roles.outranks(mod, account)) {
return null;
}
return {error: account === mod ? "That is you." : "Staff of your rank or above are for someone higher up to deal with."};
};
switch (route) {
// who is signed in here, their role and what it allows: for a client to
@@ -564,7 +587,12 @@ const handle = async (req, res, url, from, web) => {
reply(200, {reports: reports.list(url.searchParams.get("handled") === "1"), open: reports.openCount()});
return;
// a report dealt with: for the roles that act on players (a warning is
// the least of it), not for one that only looks.
case "POST /mod/api/report":
if (!may("player.warn")) {
return;
}
done(reports.markHandled(Number(body.id)) ? {ok: "Marked as dealt with."} : {error: "No such report waiting."}, "report dealt with", "", `#${Number(body.id)}`);
return;
@@ -576,10 +604,32 @@ const handle = async (req, res, url, from, web) => {
}
case "POST /mod/api/request": {
if (body.action === "appealApprove" || body.action === "appealDeny") {
// a ban decision: for the roles that ban, and one that also lifts the
// ban on an address only for those that ban addresses.
const appeal = bans.waitingAppeal(body.id);
const liftsAddress = body.action === "appealApprove" && appeal && appeal.addressKey && bans.addressBan(appeal.addressKey);
if (!may("player.ban") || (liftsAddress && !may("address.ban"))) {
return;
}
const refusal = appeal ? refusalFor(accounts.byId(appeal.accountId)) : null;
if (refusal) {
done(refusal);
return;
}
const result = staff.answerAppeal(body.id, body.action === "appealApprove", body.reply, mod.username);
done(result, body.action === "appealApprove" ? "appeal approved" : "appeal denied", result.username, bans.clean(body.reply, bans.MAX_REPLY));
}
else if (body.action === "approve" || body.action === "deny") {
// a new name: for the roles that judge names.
if (!may("player.names")) {
return;
}
const request = support.nameRequestById(body.id);
const refusal = request ? refusalFor(accounts.byId(request.accountId)) : null;
if (refusal) {
done(refusal);
return;
}
const result = staff.answerNameRequest(body.id, body.action === "approve");
done(result, body.action === "approve" ? "name request approved" : "name request denied", result.username);
}
@@ -603,8 +653,18 @@ const handle = async (req, res, url, from, web) => {
return;
}
// A device ban lifted (lib/devices.js).
// A device ban lifted (lib/devices.js): for the roles that give them
// (act's unbanDevices), and not one made with staff of their rank or above.
case "POST /mod/api/device": {
if (!may("address.ban")) {
return;
}
const ban = devices.banById(body.id);
const refusal = ban ? refusalFor(accounts.byId(ban.accountId)) : null;
if (refusal) {
done(refusal);
return;
}
const result = staff.unbanDevices(body.id, mod.username);
done(result, "hardware ban lifted", result.username || "");
return;
@@ -626,9 +686,19 @@ const handle = async (req, res, url, from, web) => {
return;
}
// a painting judged: for the roles that judge what players make, and
// never their own or one by staff of their rank or above.
case "POST /mod/api/masterpiece": {
if (!may("items.approve")) {
return;
}
const id = String(body.id || "");
const maker = masterpieces.creatorOf(id);
const refusal = refusalFor(maker);
if (refusal) {
done(refusal);
return;
}
const result = body.action === "approve"
? (world.approveMasterpiece(id) ? {ok: "Approved."} : {error: "No such painting waiting."})
: body.action === "reject" || body.action === "remove"