fix(staff): a Discord sign-in asks for the 2FA code, and the bot needs one too

Since 7dee290 a Discord account linked to a staff member opened the
moderator panel for 12 hours on Discord's word alone, with no password and
no 2FA code, though the normal sign-in asks for both every time; and since
b11ae1d the bot took /moderate and /burrow commands from that Discord
account alone. The link outlives a new password and "sign out
everywhere", so a taken-over Discord account was enough to act as the
staff member. The admin dashboard's Discord sign-in (adminDashboardAccess)
skipped its password the same way.

- /mod/discord/callback and /admin/discord/callback no longer sign in:
  they keep a pending sign-in for 5 minutes (a Strict cookie) and the page
  asks for the linked account's 2FA code (POST .../api/discord/code). Five
  wrong codes and it must start again at Discord. The admin one also needs
  the account to have 2FA on and not be locked.
- the bot's commands and buttons count only for a staff member with a
  panel session that took a code (modpanel.discordBot.commandActor): the
  password sign-in, or Discord and a code; not the game's token sign-in. A
  new password, signing out everywhere or 2FA turned off end those
  sessions (forget), and so the bot's use. Whose Discord it is still keeps
  linked staff out of /discord moderation, and lets them close tickets.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
SnipzilandClaude Opus 5.5 committed 2026-10-21 22:54:26 -04:00
1 parent 83c2fc3b0b
commit 3b53c8dab8
5 files changed
+278 -25

No files matched your search

+52
View File
@@ -392,6 +392,12 @@
</div>
<button class="primary" id="gate-button">Sign in</button>
</form>
<form id="discord-code-form" hidden>
<p class="hint">Discord confirmed who you are. Enter that account's 2FA code to finish signing in.</p>
<label for="discord-code">2FA code</label>
<input id="discord-code" inputmode="numeric" autocomplete="one-time-code" maxlength="20" spellcheck="false" required>
<button class="primary" id="discord-code-button">Finish signing in</button>
</form>
<button type="button" id="discord-sign-in" hidden>Sign in with Discord</button>
<p class="hint" id="discord-gate-hint" hidden>Only Discord accounts explicitly allowed by the owner can use this.</p>
<p class="status" id="gate-status" role="status"></p>
@@ -1261,6 +1267,38 @@
location.href = "/dashboard/admin/discord/login";
});
// after Discord: the linked account's 2FA code (POST discord/code)
const discordGate = (codeStep, message) => {
history.replaceState(null, "", location.pathname + location.hash);
showGate(message);
$("gate-form").hidden = codeStep;
$("discord-code-form").hidden = !codeStep;
if (codeStep) {
$("discord-sign-in").textContent = "Start again with Discord";
$("discord-code").focus();
}
};
$("discord-code-form").addEventListener("submit", async event => {
event.preventDefault();
$("discord-code-button").disabled = true;
const result = await api("discord/code", {code: $("discord-code").value.trim()});
$("discord-code-button").disabled = false;
$("discord-code").value = "";
if (result.ok) {
$("discord-code-form").hidden = true;
$("gate-form").hidden = false;
state = {needsSetup: false, needsSetupCode: false, signedIn: true};
showPanel();
}
else if (result.data.expired) {
discordGate(false, result.data.error);
}
else {
setStatus($("gate-status"), result.data.error || "That did not work.", true);
}
});
$("sign-out").addEventListener("click", async () => {
await api("logout", {});
state.signedIn = false;
@@ -3514,9 +3552,23 @@
showGate("The server did not answer.");
return;
}
const discordResult = new URLSearchParams(location.search).get("discord");
if (state.signedIn) {
showPanel();
}
else if (discordResult === "code") {
discordGate(true, "");
}
else if (discordResult) {
discordGate(false, {
denied: "That Discord account is not allowed to sign in here.",
twostep: "Turn on 2FA for the linked account first.",
expired: "The Discord sign-in request expired. Try again.",
cancelled: "Discord sign-in was cancelled.",
discord: "Discord could not confirm that sign-in. Try again.",
off: "Discord sign-in is not configured.",
}[discordResult] || "");
}
else {
showGate();
}