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

+8 -1
View File
@@ -308,6 +308,13 @@ const unban = id => {
return ban;
};
// one ban as kept, with the account it was made with (accountId), or null:
// for the moderator panel to see whose it is before lifting it.
const banById = id => {
const row = db().prepare("SELECT * FROM device_bans WHERE id = ?").get(Number(id));
return row ? banRow(row) : null;
};
// the bans, newest first: their ids, and the accounts that used them.
const MAX_LISTED_ACCOUNTS = 20;
const list = () => db().prepare("SELECT * FROM device_bans ORDER BY id DESC").all().map(banRow)
@@ -418,4 +425,4 @@ const noteLauncher = (token, hasIds) => {
};
const launcherOutdated = token => outdatedTokens.has(tokenKey(token));
module.exports = {noteLauncher, launcherOutdated, load, read, banOf, banOfAccount, seen, alts, knownFor, banAccount, accountsUnder, unban, list, idsFor, bansOfAccount, search, bannedId, alerts, alertsOf, forget, clientHash};
module.exports = {noteLauncher, launcherOutdated, load, read, banOf, banOfAccount, seen, alts, knownFor, banAccount, accountsUnder, unban, banById, list, idsFor, bansOfAccount, search, bannedId, alerts, alertsOf, forget, clientHash};
+12
View File
@@ -111,6 +111,13 @@ const signOutOthers = (account, req) => {
}
};
// ends the account's sessions in the moderator panel (lib/modpanel.js, which
// needs this file, so it is asked for when used): with the others when the
// password changes or the owner signs out everywhere, and when the account
// locks or turns 2FA off, so that a session from before does not come back
// with it.
const endStaffSessions = account => require("./modpanel.js").forget(account);
const twoStepOf = account => ({on: totp.isOn(account), since: account.totp ? account.totp.since : null,
recoveryLeft: account.totp ? account.totp.recovery.length : 0, devices: totp.freshDevices(account).length, deviceDays: totp.DEVICE_DAYS});
@@ -292,6 +299,7 @@ const act = (account, body, req, from, res) => {
}
world.moderation.actions.kick(account);
signOutOthers(account, req);
endStaffSessions(account);
console.log(`[account] "${logText(account.username)}" changed their password from ${logText(from.address)}`);
return {ok: "Password changed."};
}
@@ -311,6 +319,7 @@ const act = (account, body, req, from, res) => {
// out of the game now, and no saved sign-in gets back in.
accounts.revokeTokens(account);
world.moderation.actions.kick(account);
endStaffSessions(account);
}
accounts.save(account);
console.log(`[account] "${logText(account.username)}" ${logText(account.locked ? "locked" : "unlocked")} from ${logText(from.address)}`);
@@ -364,6 +373,7 @@ const act = (account, body, req, from, res) => {
}
totp.turnOff(account);
accounts.save(account);
endStaffSessions(account);
res.setHeader("Set-Cookie", cookieHeader("", 0, DEVICE_COOKIE));
console.log(`[account] "${logText(account.username)}" turned two-step sign-in off from ${logText(from.address)}`);
return {ok: "2FA is off."};
@@ -467,6 +477,7 @@ const act = (account, body, req, from, res) => {
accounts.save(account);
world.moderation.actions.kick(account);
signOutOthers(account, req);
endStaffSessions(account);
return {ok: "Signed out everywhere."};
// for good: the password again, and the username typed out.
case "delete": {
@@ -479,6 +490,7 @@ const act = (account, body, req, from, res) => {
const name = account.username;
world.disconnect(account);
signOutOthers(account, null);
endStaffSessions(account);
erase(account);
console.log(`[account] "${logText(name)}" deleted their account from ${logText(from.address)}`);
return {ok: "Account deleted.", deleted: true};
+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"
+4 -4
View File
@@ -17,15 +17,15 @@ const totp = require("./totp.js");
const PERMISSIONS = {
"player.view": "see players, chat, reports, requests, bans and paintings in the moderator panel, and keep notes on players (!note, !notes)",
"staff.list": "see which staff are online (!staff)",
"player.warn": "warn a player, take a warning back and send them a message (!warn, !unwarn, !warnings, !message)",
"player.warn": "warn a player, take a warning back, send them a message and mark a report dealt with (!warn, !unwarn, !warnings, !message)",
"player.goto": "go to the room a player is in (!goto)",
"chat.silence": "silence and unsilence a player (!silence)",
"player.kick": "disconnect a player (!kick)",
"player.summon": "bring a player to the room you are in (!summon)",
"staff.invisible": "go unseen in rooms, as the game's moderators could (!invisible)",
"player.ban": "ban, unban and change a ban's reason",
"player.names": "reject or accept a name, clear a bio, remove a player's Jammer Wall posts",
"address.ban": "ban the address a player last signed in from",
"player.ban": "ban, unban, change a ban's reason and answer ban appeals",
"player.names": "reject or accept a name, answer requests for a new one, clear a bio, remove a player's Jammer Wall posts",
"address.ban": "ban the address a player last signed in from, or the computers they use, and lift those bans",
"items.approve": "approve or turn away the items and pictures players make, when the admin has asked for that",
"items.create": "make new items from the game's art, change and delete them, lock items out of the item finder and take items from players (!item, !lock, !unlock, !locked, !take)",
};