Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = "com.extantape"
version = "0.2.2"
version = "0.2.3"

java {
toolchain.languageVersion.set(JavaLanguageVersion.of(25))
Expand Down
14 changes: 14 additions & 0 deletions docs/releases/v0.2.3.md
Original file line number Diff line number Diff line change
@@ -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.
7 changes: 7 additions & 0 deletions docs/test-audit.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/extantape/bluemapauth/web/JsonFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,11 @@ static String players(String json, Function<Set<UUID>, Set<UUID>> 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\":[]}";
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/extantape/bluemapauth/web/MapServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Access.Viewer> 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;
}
Expand Down
14 changes: 10 additions & 4 deletions src/main/java/com/extantape/bluemapauth/web/RateLimiter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long> 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) {
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/extantape/bluemapauth/web/MapServerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading