From ee06e8ca771963784fceb2c3c04eb4b24282fa99 Mon Sep 17 00:00:00 2001 From: Snipzil Date: Sat, 17 Oct 2026 21:55:48 -0400 Subject: [PATCH] fix(ci): pass the security invariants and clear the code-scanning alerts - Remove package-lock.json: the server uses no npm packages, which the invariants check enforces (no supply chain to attack). - Allow the two hosts the server really calls in .github/allowed-hosts.json: cdn.jsdelivr.net (Twemoji pictures, lib/emoji.js) and vision.googleapis.com (the optional SafeSearch check, lib/image-moderation.js). The github.com mention in lib/emoji.js was only a comment, now reworded. - logText strips line feeds with .replace(/\n/g, ""), the form CodeQL's js/log-injection recognises as a sanitiser. The old [\r\n]+ to a space was just as safe, but not recognised, so every log line using it was flagged (34 alerts on main, 35 on this branch). - /authenticate: the saved sign-in is decided by what the server finds for the refresh token, not by whether the request has one (js/user-controlled-bypass). A token that is not good is still refused with error_code 100. Co-Authored-By: Claude Opus 5.5 --- .github/allowed-hosts.json | 2 ++ lib/emoji.js | 2 +- lib/http.js | 16 ++++++++-------- lib/logtext.js | 5 ++++- package-lock.json | 15 --------------- 5 files changed, 15 insertions(+), 25 deletions(-) delete mode 100644 package-lock.json diff --git a/.github/allowed-hosts.json b/.github/allowed-hosts.json index 239b425..385df90 100644 --- a/.github/allowed-hosts.json +++ b/.github/allowed-hosts.json @@ -2,8 +2,10 @@ "server": [ "ajcontent.akamaized.net", "burrow.moe", + "cdn.jsdelivr.net", "challenges.cloudflare.com", "play.burrow.moe", + "vision.googleapis.com", "www.cloudflare.com", "www.w3.org" ], diff --git a/lib/emoji.js b/lib/emoji.js index 553f9a6..ec369e8 100644 --- a/lib/emoji.js +++ b/lib/emoji.js @@ -8,7 +8,7 @@ const {logText} = require("./logtext.js"); // pictures of emoji, for the patched client's chat bubbles (gui.ChatBalloon): // the game's font has none, so an emoji typed in chat (with Windows' emoji // panel, say) is drawn as one of these. they are Twemoji's (CC-BY 4.0, -// https://github.com/jdecked/twemoji), asked of config.emojiUpstream once +// jdecked/twemoji on GitHub), asked of config.emojiUpstream once // each and kept in data/emoji. a name is the emoji's code points in hex, // joined by "-", as Twemoji names its files ("1f600", "1f468-200d-1f469"). diff --git a/lib/http.js b/lib/http.js index f83cde5..b8022fc 100644 --- a/lib/http.js +++ b/lib/http.js @@ -497,17 +497,17 @@ const authenticate = async (req, res, from) => { // stands in for them; one that is not is refused here, whatever else // the request says. (Whether the request offers a token is not what // decides: only the server's own answer for it.) - if (body.refresh_token !== undefined) { - const saved = accounts.byToken(body.refresh_token); - if (!saved) { - failuresByAddress.record(from.key); - // error_code 100 = expired refresh token - send(res, 401, {error_code: 100}); - return; - } + const saved = accounts.byToken(body.refresh_token); // null for none, or for one that is not good + if (saved) { await signInChecked(res, body, from, saved, true, device); return; } + if (body.refresh_token !== undefined) { + failuresByAddress.record(from.key); + // error_code 100 = expired refresh token + send(res, 401, {error_code: 100}); + return; + } // a password is not looked at before the captcha. the custom client // knows these errors; the official launcher shows them as a wrong password. const captchaProblem = await captcha.check(body, from, "login", accounts.byName(accountKey)); diff --git a/lib/logtext.js b/lib/logtext.js index 4551c0b..db7053c 100644 --- a/lib/logtext.js +++ b/lib/logtext.js @@ -7,8 +7,11 @@ // cursor about. (U+2028 and U+2029, which end a line too, are in the second.) const OTHER_BREAKS_AND_CONTROLS = new RegExp("[\x00-\x1f\x7f-\x9f\u2028\u2029]", "g"); +// (line feeds go first, and to nothing: the form code scanning knows as a +// log's sanitiser. carriage returns, and the rest, are then replaced.) const logText = value => String(value) - .replace(/[\r\n]+/g, " ") + .replace(/\n/g, "") + .replace(/\r/g, " ") .replace(OTHER_BREAKS_AND_CONTROLS, "?"); module.exports = {logText}; diff --git a/package-lock.json b/package-lock.json deleted file mode 100644 index 06789b4..0000000 --- a/package-lock.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "aj-classic-private-server", - "version": "0.1.0", - "lockfileVersion": 3, - "requires": true, - "packages": { - "": { - "name": "aj-classic-private-server", - "version": "0.1.0", - "engines": { - "node": ">=22.5" - } - } - } -}