feat(dashboard): unify secure staff administration

Provide a single /dashboard entry point for owner and staff tools, with Discord OAuth sign-in for approved owner accounts and active staff. Add owner-managed dashboard access grants, staff server health and update visibility, filtering, moderation improvements, item controls, and per-animal clothing restrictions.

Replace staff-triggered password and 2FA resets with email-verified account recovery. Persist validated recovery addresses, use short-lived hashed recovery tokens, expose recovery flows in registration and account pages, and keep mail delivery disabled until its webhook configuration is present.

Cover dashboard aliases, recovery restrictions, Discord access, monitoring, item locks, wear rules, and staff behavior with regression tests.
This commit is contained in:
Snipzil committed 2026-10-19 10:09:35 -04:00
1 parent 4997315239
commit 7dee29010a
27 files changed
+2303 -346

No files matched your search

+60 -5
View File
@@ -50,6 +50,19 @@ const MIME = {
".otf": "font/otf",
};
// The desktop webview caches the SWF aggressively. Include the local SWF's
// timestamp in its URL so a freshly built client is actually picked up after
// the server restarts, without making an operator remember to bump a config
// value by hand.
const clientRevision = () => {
try {
return Math.floor(fs.statSync(config.clientSwf).mtimeMs).toString(36);
}
catch (_) {
return "unknown";
}
};
const flashVars = () => ({
content: config.baseUrl,
// the game's own server to the SWF, whatever its name: it loads the card
@@ -69,7 +82,7 @@ const flashVars = () => ({
// member or not may be chosen on any server (lib/accounts.js)
membershipChoice: true,
smoke_version: config.deployVersion,
clientURL: `${config.baseUrl}${config.deployVersion}/ajclient.swf?v=${config.buildVersion}`,
clientURL: `${config.baseUrl}${config.deployVersion}/ajclient.swf?v=${config.buildVersion}-${clientRevision()}`,
startupRoom: config.startupRoom,
// "-1" turns the client's stats socket off.
sbStatTrackerIp: "-1",
@@ -293,7 +306,7 @@ const repeatedError = text => {
const THEMED_ROOM = /^(\d+)\/roomDefs\/theme_(\d+)\/(.+)$/;
// the web pages, as against what the game and the client load
const SITE_PAGES = /^\/(?:register|terms|privacy|commands|shop|account|mod|download)?\/?$/;
const SITE_PAGES = /^\/(?:register|terms|privacy|commands|shop|account|mod|admin|dashboard|download)?\/?$/;
// the installers /download offers, those of them config.downloadsDir has
const DOWNLOADS = [
@@ -652,22 +665,54 @@ const handle = async (req, res) => {
return;
}
const isAdmin = url.pathname === "/admin" || url.pathname.startsWith("/admin/");
const dashboardAdmin = url.pathname === "/dashboard/admin" || url.pathname.startsWith("/dashboard/admin/")
|| url.pathname === "/dashboard/api/admin" || url.pathname.startsWith("/dashboard/api/admin/");
const dashboardStaff = url.pathname === "/dashboard/staff" || url.pathname.startsWith("/dashboard/staff/")
|| url.pathname === "/dashboard/api/staff" || url.pathname.startsWith("/dashboard/api/staff/");
const isDashboard = url.pathname === "/dashboard" || dashboardAdmin || dashboardStaff;
const isAdmin = url.pathname === "/admin" || url.pathname.startsWith("/admin/") || dashboardAdmin;
const isAccount = url.pathname === "/account" || url.pathname.startsWith("/account/");
const isMod = url.pathname === "/mod" || url.pathname.startsWith("/mod/");
const isMod = url.pathname === "/mod" || url.pathname.startsWith("/mod/") || dashboardStaff;
// the pages that keep a cookie answer only under this server's own names:
// a request sent here by a page of another name (one whose name was made
// to point at this machine, say) is not theirs to make. nor is such a
// request ever this machine's own, wherever it came from.
if (!limits.hostAllowed(req)) {
if (isAdmin || isAccount || isMod) {
if (isDashboard || isAdmin || isAccount || isMod) {
send(res, 421, {error: "wrong_host"});
return;
}
from.local = false;
}
// One entry point for the owner and staff dashboards. The old addresses
// stay as bookmark-friendly redirects; their APIs remain available for
// installed tools and are not redirected.
if (req.method === "GET" && url.pathname === "/dashboard/") {
res.writeHead(302, {Location: `/dashboard${url.search}`, "Content-Length": 0});
res.end();
return;
}
if (req.method === "GET" && url.pathname === "/dashboard") {
res.setHeader("Cache-Control", "no-store");
res.setHeader("X-Frame-Options", "DENY");
res.setHeader("X-Content-Type-Options", "nosniff");
res.setHeader("Referrer-Policy", "no-referrer");
send(res, 200, await fs.promises.readFile(path.join(config.publicDir, "dashboard.html")), "text/html; charset=utf-8");
return;
}
if (req.method === "GET" && url.pathname === "/admin") {
res.writeHead(302, {Location: "/dashboard/admin", "Content-Length": 0});
res.end();
return;
}
if (req.method === "GET" && url.pathname === "/mod") {
res.writeHead(302, {Location: "/dashboard/staff", "Content-Length": 0});
res.end();
return;
}
// the admin panel sets its own, stricter headers: none of the cross-origin
// allowances below apply to it. on a public server it is not there at all
// for anyone but this machine and the addresses named (config.adminAllow).
@@ -676,6 +721,11 @@ const handle = async (req, res) => {
send(res, 404, "Not found", "text/plain");
return;
}
if (dashboardAdmin) {
url.pathname = url.pathname.startsWith("/dashboard/api/admin")
? url.pathname.replace("/dashboard/api/admin", "/admin/api")
: url.pathname.replace("/dashboard/admin", "/admin");
}
if (url.pathname === "/admin/api/itemart") {
res.setHeader("Cache-Control", "no-store");
await itemArtUpload(req, res, url, from, null, panel.signedIn);
@@ -697,6 +747,11 @@ const handle = async (req, res) => {
// and the moderator panel (lib/modpanel.js), which is there for anyone to
// reach: its moderators are players, wherever they are.
if (dashboardStaff) {
url.pathname = url.pathname.startsWith("/dashboard/api/staff")
? url.pathname.replace("/dashboard/api/staff", "/mod/api")
: url.pathname.replace("/dashboard/staff", "/mod");
}
if (isMod && url.pathname === "/mod/api/itemart") {
res.setHeader("Cache-Control", "no-store");
await itemArtUpload(req, res, url, from, modpanel.signedInAs);