Skip to content

Commit 1686cb7

Browse files
committed
Block connections if the default tokens are still configured
1 parent 414ea18 commit 1686cb7

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

INSTALLATION.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ The latest versions of BungeeGuard can be found from:
3232
4. Navigate to `/plugins/BungeeGuard/config.yml`. Add the token(s) generated by the proxy(ies) to the `allowed-tokens` list.
3333
> e.g.
3434
> ```yml
35-
> # Allowed authentication tokens.
36-
> allowed-tokens:
37-
> - "AUSXEwebkOGVnbihJM8gBS0QUutDzvIG009xoAfo1Huba9pGvhfjrA21r8dWVsa8"
38-
> ```
35+
> # Allowed authentication tokens.
36+
> allowed-tokens:
37+
> - "AUSXEwebkOGVnbihJM8gBS0QUutDzvIG009xoAfo1Huba9pGvhfjrA21r8dWVsa8"
38+
> ```
39+
> **Please make sure you remove the default tokens, so the only values in the list are your allowed tokens.**
3940
5. Run `bungeeguard reload` from console.

bungeeguard-backend/src/main/java/me/lucko/bungeeguard/backend/TokenStore.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,14 @@ public boolean isAllowed(String token) {
5959
return this.allowedTokens.contains(token);
6060
}
6161

62+
/**
63+
* Has the server owner bothered to configure their tokens correctly...?
64+
*
65+
* @return true if BungeeGuard has not yet been configured
66+
*/
67+
public boolean isUsingDefaultConfig() {
68+
return this.allowedTokens.contains("the token generated by the proxy goes here") ||
69+
this.allowedTokens.contains("you can add as many as you like.");
70+
}
71+
6272
}

bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/BungeeCordHandshake.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public static BungeeCordHandshake decodeAndVerify(String handshake, TokenStore t
7575
}
7676

7777
private static BungeeCordHandshake decodeAndVerify0(String handshake, TokenStore tokenStore) throws Exception {
78+
if (tokenStore.isUsingDefaultConfig()) {
79+
return new Fail(Fail.Reason.INCORRECT_TOKEN, "Allowed tokens have not been configured! Please refer to https://github.com/lucko/BungeeGuard/blob/master/INSTALLATION.md for help.");
80+
}
81+
7882
if (handshake.length() > HANDSHAKE_LENGTH_LIMIT) {
7983
return new Fail(Fail.Reason.INVALID_HANDSHAKE, "handshake length " + handshake.length() + " is > " + HANDSHAKE_LENGTH_LIMIT);
8084
}

bungeeguard-spigot/src/main/java/me/lucko/bungeeguard/spigot/BungeeGuardBackendPlugin.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,17 @@ public void onEnable() {
5454
this.tokenStore = new TokenStore(this);
5555
this.tokenStore.load();
5656

57+
if (!getServer().spigot().getSpigotConfig().getBoolean("settings.bungeecord", false)) {
58+
getLogger().severe("------------------------------------------------------------");
59+
getLogger().severe("'settings.bungeecord' is set to false in spigot.yml.");
60+
getLogger().severe("");
61+
getLogger().severe("BungeeGuard cannot function unless this property is set to true.");
62+
getLogger().severe("The server will now shutdown as a precaution.");
63+
getLogger().severe("------------------------------------------------------------");
64+
getServer().shutdown();
65+
return;
66+
}
67+
5768
if (isPaperHandshakeEvent()) {
5869
getLogger().info("Using Paper's PlayerHandshakeEvent to listen for connections.");
5970

0 commit comments

Comments
 (0)