diff --git a/README.md b/README.md index 749eef0..523884b 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ BlueMapAuth for Paper: BlueMap's web map behind a sign-in, showing each player only the worlds and players they're allowed to see. -**Status:** early, version 0.2.2. 38 HTTP and config tests pass, plus a bot test (27/27 direct, 28/28 through a local Caddy running the staged site block, and 8/8 without Mayor and LuckPerms, 2026-11-24) on a throwaway Paper 26.1.2 server with the real BlueMap 5.29, LuckPerms 5.5, Mayor and WelcomeWagon, signing in through WelcomeWagon's "Open the map" over HTTP. The hand-off page was checked in a real browser (Chromium, 2026-11-11, against made-up data on localhost; `BrowserDemo` in the test sources). The token leaves the address bar, the cookie is invisible to scripts, a reused link explains itself, and the page has no policy errors. On a copy of a real server on Paper 26.2 and 26.3 build 249 (2026-11-14) it loaded with no errors, switched off, so serving the map on 26.2 and 26.3 is still untested, as is running behind Caddy. +**Status:** early, version 0.2.3. 40 HTTP and config tests pass, plus a bot test (27/27 direct on 0.2.3; 28/28 through a local Caddy running the staged site block and 8/8 without Mayor and LuckPerms on 0.2.2, 2026-11-24) on a throwaway Paper 26.1.2 server with the real BlueMap 5.29, LuckPerms 5.5, Mayor and WelcomeWagon, signing in through WelcomeWagon's "Open the map" over HTTP. The hand-off page was checked in a real browser (Chromium, 2026-11-11, against made-up data on localhost; `BrowserDemo` in the test sources). The token leaves the address bar, the cookie is invisible to scripts, a reused link explains itself, and the page has no policy errors. On a copy of a real server on Paper 26.2 and 26.3 build 249 (2026-11-14) it loaded with no errors, switched off, so serving the map on 26.2 and 26.3 is still untested, as is running behind Caddy. ## What it does diff --git a/build.gradle.kts b/build.gradle.kts index 38c44ff..85dba92 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -3,7 +3,7 @@ plugins { } group = "com.extantape" -version = "0.2.2" +version = "0.2.3" java { toolchain.languageVersion.set(JavaLanguageVersion.of(25)) diff --git a/docs/releases/v0.2.3.md b/docs/releases/v0.2.3.md new file mode 100644 index 0000000..78004a7 --- /dev/null +++ b/docs/releases/v0.2.3.md @@ -0,0 +1,14 @@ +Two small follow-ups from Infrastructure's check of 0.2.2 (K70, 2026-11-24). + +## What changed + +- **A player entry with no "foreign" flag is left out,** as the 0.2.2 notes promised. BlueMap 5.29 always writes the flag, so this only matters if a later BlueMap stops. +- **A working map link always signs in,** even while junk tries have filled the site-wide limit. Before, a few addresses sending junk could lock real players out for a minute. Failed tries are still slowed once the limit is full, and every try still counts toward each visitor's own limit. The links' 256 random bits are what stop guessing. + +## Installing over 0.2.2, 0.2.1 or 0.2.0 + +With the server stopped, swap in `BlueMapAuth-0.2.3.jar`. Nothing else changes. + +## Tested + +40 unit and HTTP tests, including an entry with no flag and a real sign-in after 70 junk tries from five addresses. The direct bot run against the real BlueMap 5.29 passed 27/27 on Paper 26.1.2. The Caddy and fail-closed runs weren't repeated; 0.2.2 passed both and nothing they check changed. diff --git a/docs/test-audit.md b/docs/test-audit.md index 3bbf005..fc4f13b 100644 --- a/docs/test-audit.md +++ b/docs/test-audit.md @@ -4,6 +4,13 @@ Kept by this repo's owning session, per `~/Code/CLAUDE.md`, "Test self-audits". + +## 2026-11-24: 0.2.2 check leftovers (0.2.3) + +- Promises: a missing foreign flag counts as foreign; a working link signs in even when the site-wide limit is full. +- Covered: `MapServerTest.aPlayerEntryWithNoForeignFlagIsLeftOut`, `aWorkingLinkStillSignsInWhenJunkTriesHaveFilledTheSiteWideLimit`; `RateLimiterTest.failedTriesFillTheSiteWideBudget` rewritten for the new rule. +- Gaps skipped: the proxy and fail-closed bot runs weren't rerun; neither touches the hand-off limit or the foreign flag, and 0.2.2 passed both. + ## 2026-11-24: second security review follow-ups (0.2.2) - Promises: players BlueMap marks foreign are never sent; head pictures only for visible players; any case of "live" is live; real sign-ins don't use up the site-wide limit; bad proxy entries fail at load. diff --git a/src/main/java/com/extantape/bluemapauth/web/JsonFilter.java b/src/main/java/com/extantape/bluemapauth/web/JsonFilter.java index ba09912..5af9b4e 100644 --- a/src/main/java/com/extantape/bluemapauth/web/JsonFilter.java +++ b/src/main/java/com/extantape/bluemapauth/web/JsonFilter.java @@ -52,12 +52,11 @@ static String players(String json, Function, Set> visible) { /** * A player BlueMap lists as "foreign" is in another world, and their position isn't on this map. With BlueMap's * hide-different-world off, that world may be one the viewer can't enter, such as a kids' world, so they're never - * sent (K70 review M1, 2026-11-24). A flag that isn't a plain false counts as foreign. + * sent (K70 review M1, 2026-11-24). A missing flag, or one that isn't a plain false, counts as foreign, so it fails closed. */ private static boolean foreign(JsonElement e) { JsonElement f = e.getAsJsonObject().get("foreign"); - if (f == null) return false; - return !(f.isJsonPrimitive() && f.getAsJsonPrimitive().isBoolean() && !f.getAsBoolean()); + return !(f != null && f.isJsonPrimitive() && f.getAsJsonPrimitive().isBoolean() && !f.getAsBoolean()); } static final String EMPTY_PLAYERS = "{\"players\":[]}"; diff --git a/src/main/java/com/extantape/bluemapauth/web/MapServer.java b/src/main/java/com/extantape/bluemapauth/web/MapServer.java index d36855d..7515717 100644 --- a/src/main/java/com/extantape/bluemapauth/web/MapServer.java +++ b/src/main/java/com/extantape/bluemapauth/web/MapServer.java @@ -226,8 +226,13 @@ private void handoff(HttpExchange x) throws IOException { String token = body.length > MAX_BODY ? null : tokenOf(new String(body, StandardCharsets.US_ASCII)); Optional v = token == null ? Optional.empty() : access.redeem(token); if (v.isEmpty()) { - limiter.failed(); + long siteWait = limiter.failed(); waitOut(started); + if (siteWait > 0) { + x.getResponseHeaders().set("Retry-After", Long.toString(siteWait)); + plain(x, 429, "Too many tries."); + return; + } plain(x, 403, "That link didn't work."); return; } diff --git a/src/main/java/com/extantape/bluemapauth/web/RateLimiter.java b/src/main/java/com/extantape/bluemapauth/web/RateLimiter.java index 0e1c833..e754d4a 100644 --- a/src/main/java/com/extantape/bluemapauth/web/RateLimiter.java +++ b/src/main/java/com/extantape/bluemapauth/web/RateLimiter.java @@ -29,24 +29,30 @@ public RateLimiter(int perVisitorPer10Minutes, int siteWidePerMinute, LongSuppli this.clock = clockMillis; } - /** Zero if the try may go ahead (and counts it), otherwise how many seconds until it may. */ + /** Zero if this visitor's try may go ahead (and counts it), otherwise how many seconds until it may. */ public synchronized long tryAcquire(String visitor) { long now = clock.getAsLong(); trim(site, now - SITE_WINDOW); Deque mine = visitors.computeIfAbsent(visitor, k -> new ArrayDeque<>()); trim(mine, now - VISITOR_WINDOW); if (mine.size() >= perVisitor) return seconds(mine.peekFirst() + VISITOR_WINDOW - now); - if (site.size() >= siteWide) return seconds(site.peekFirst() + SITE_WINDOW - now); mine.addLast(now); if (visitors.size() > MAX_VISITORS_TRACKED) forgetIdle(now); return 0; } - /** A try that didn't work: counts toward the site-wide limit. */ - public synchronized void failed() { + /** + * A try that didn't work: counts toward the site-wide limit, and says how many seconds everyone's failed tries + * must wait, or zero. A link that works is never refused by the site-wide limit, so junk tries from a few + * addresses can't lock real players out (K70 review L2, 2026-11-24). The links' 256 random bits are what stop + * guessing; this only slows the feedback to a flood. + */ + public synchronized long failed() { long now = clock.getAsLong(); trim(site, now - SITE_WINDOW); + if (site.size() >= siteWide) return seconds(site.peekFirst() + SITE_WINDOW - now); site.addLast(now); + return 0; } private void forgetIdle(long now) { diff --git a/src/test/java/com/extantape/bluemapauth/web/MapServerTest.java b/src/test/java/com/extantape/bluemapauth/web/MapServerTest.java index 8523abc..99e7fcc 100644 --- a/src/test/java/com/extantape/bluemapauth/web/MapServerTest.java +++ b/src/test/java/com/extantape/bluemapauth/web/MapServerTest.java @@ -219,6 +219,28 @@ void aPlayerInAnotherWorldIsNeverSentEvenIfReachable() throws Exception { assertFalse(get("/maps/family_map/live/players.json", kid).body().contains(MUM.toString()), "an odd flag counts as foreign"); } + @Test + void aPlayerEntryWithNoForeignFlagIsLeftOut() throws Exception { + String kid = signIn(KID); + playersJson = "{\"players\":[" + player(KID) + "," + player(MUM).replace(",\"foreign\":false", "") + "]}"; + var r = get("/maps/family_map/live/players.json", kid).body(); + assertTrue(r.contains(KID.toString()) && !r.contains(MUM.toString()), r); + } + + @Test + void aWorkingLinkStillSignsInWhenJunkTriesHaveFilledTheSiteWideLimit() throws Exception { + // K70 review L2: 60 junk tries in a minute used to lock real players out too. + int refused = 0; + for (int i = 0; i < 70; i++) { + var r = http.send(HttpRequest.newBuilder(URI.create("http://127.0.0.1:" + server.port() + "/handoff")).header("Origin", ORIGIN) + .header("Content-Type", "application/x-www-form-urlencoded").header("X-Forwarded-For", "198.51.100." + (i / 15)) + .POST(HttpRequest.BodyPublishers.ofString("token=" + "J".repeat(43))).build(), HttpResponse.BodyHandlers.ofString()); + if (r.statusCode() == 429) refused++; + } + assertTrue(refused > 0, "junk is slowed once the site-wide limit is full"); + signIn(MUM); // throws unless the hand-off answers 204 + } + @Test void anyCaseOfLiveIsTreatedAsLive() throws Exception { String kid = signIn(KID); diff --git a/src/test/java/com/extantape/bluemapauth/web/RateLimiterTest.java b/src/test/java/com/extantape/bluemapauth/web/RateLimiterTest.java index b1442bc..96b52eb 100644 --- a/src/test/java/com/extantape/bluemapauth/web/RateLimiterTest.java +++ b/src/test/java/com/extantape/bluemapauth/web/RateLimiterTest.java @@ -21,10 +21,11 @@ void goodSignInsFromAFewAddressesDontLockOutEveryoneElse() { @Test void failedTriesFillTheSiteWideBudget() { RateLimiter l = new RateLimiter(20, 5, now::get); - for (int i = 0; i < 5; i++) { assertEquals(0, l.tryAcquire("10.0.0." + i)); l.failed(); } - assertTrue(l.tryAcquire("203.0.113.9") > 0, "after 5 failures in a minute, everyone waits"); + for (int i = 0; i < 5; i++) { assertEquals(0, l.tryAcquire("10.0.0." + i)); assertEquals(0, l.failed()); } + assertEquals(0, l.tryAcquire("203.0.113.9"), "a real player's try still goes ahead"); + assertTrue(l.failed() > 0, "but another failure in that minute is told to wait"); now.addAndGet(61_000); - assertEquals(0, l.tryAcquire("203.0.113.9"), "and a minute later it clears"); + assertEquals(0, l.failed(), "and a minute later it clears"); } @Test