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 bungeeguard-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.10</version>
<version>1.4.11</version>
</parent>

<artifactId>bungeeguard-backend</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion bungeeguard-bungee/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.10</version>
<version>1.4.11</version>
</parent>

<artifactId>bungeeguard-bungee</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions bungeeguard-spigot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.10</version>
<version>1.4.11</version>
</parent>

<artifactId>bungeeguard-spigot</artifactId>
<version>1.4.10</version>
<version>1.4.11</version>

<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ private static BungeeCordHandshake decodeAndVerify0(String handshake, TokenStore
String[] split = handshake.split("\00");
boolean hasProperties = split.length >= 4 && isPropertiesArray(split[split.length - 1]);
int socketAddressIndex = split.length - (hasProperties ? 3 : 2);
int floodgateDataIndex = findFloodgateDataIndex(split, socketAddressIndex);
int validatedFloodgateMarkerIndex = findValidatedFloodgateMarkerIndex(split, socketAddressIndex);
boolean hasValidatedFloodgateMarker = validatedFloodgateMarkerIndex >= 1
&& FloodgateHandshakeIntegration.consumeValidatedMarker(split[validatedFloodgateMarkerIndex]);
boolean isFloodgate = floodgateDataIndex >= 1 || hasValidatedFloodgateMarker;

if (isFloodgate) {
// Never bypass Java token validation based only on a client-supplied ^Floodgate^ string.
// The encrypted marker is normally consumed by Floodgate before this listener runs; our
// private marker is the only bypass accepted here because it was minted after validation.
if (hasValidatedFloodgateMarker) {
int uuidIndex = hasProperties ? split.length - 2 : split.length - 1;
if (socketAddressIndex < 1 || uuidIndex <= socketAddressIndex) {
return new Fail(Fail.Reason.INVALID_HANDSHAKE, encodeBase64(handshake));
Expand Down Expand Up @@ -210,24 +211,6 @@ private static boolean isPropertiesArray(String value) {
return trimmed.startsWith("[") && trimmed.endsWith("]");
}

/**
* Finds Floodgate's encrypted payload among the hostname components, before the
* forwarded client address and UUID. Returns -1 when the handshake has no marker.
*/
private static int findFloodgateDataIndex(String[] split, int socketAddressIndex) {
if (socketAddressIndex <= 1) {
return -1;
}

for (int i = 1; i < socketAddressIndex; i++) {
String field = split[i];
if (field.startsWith("^Floodgate^") && field.length() > "^Floodgate^".length()) {
return i;
}
}
return -1;
}

public static String encodeBase64(String s) {
return Base64.getEncoder().encodeToString(s.getBytes(StandardCharsets.UTF_8));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,13 @@ private static TokenStore defaultTokenStore() {
}

@Test
public void acceptsCurrentFloodgateMarkerAndDoesNotRequireBungeeGuardToken() {
String payload = "^Floodgate^>encrypted-bedrock-payload";
public void rejectsUnvalidatedFloodgatePayloadMarker() {
String payload = "^Floodgate^>client-supplied-data";
String handshake = String.join("\00", HOST, payload, IP, UUID_VALUE.toString(), "[]");

BungeeCordHandshake result = BungeeCordHandshake.decodeAndVerify(handshake, configuredTokenStore());

assertTrue("Floodgate should be accepted by BungeeGuard's token gate", result instanceof BungeeCordHandshake.Success);
BungeeCordHandshake.Success success = (BungeeCordHandshake.Success) result;
assertEquals(HOST + "\00" + payload, success.serverHostname());
assertEquals(IP, success.socketAddressHostname());
assertEquals(UUID_VALUE, success.uniqueId());
assertEquals("[]", success.propertiesJson());
assertTrue("A client-supplied Floodgate-looking string must not bypass token validation", result instanceof BungeeCordHandshake.Fail);
}

@Test
Expand Down Expand Up @@ -99,37 +94,33 @@ public void forgedFloodgateIntegrationMarkerDoesNotBypassTokenValidation() {
}

@Test
public void recognizesFloodgateMarkerAfterAdditionalHostnameComponent() {
String payload = "^Floodgate^>encrypted-bedrock-payload";
public void rejectsUnvalidatedFloodgateMarkerAfterAdditionalHostnameComponent() {
String payload = "^Floodgate^>client-supplied-data";
String handshake = String.join("\00", HOST, "education-forwarded-host", payload, IP, UUID_VALUE.toString(), "[]");

BungeeCordHandshake result = BungeeCordHandshake.decodeAndVerify(handshake, configuredTokenStore());

assertTrue(result instanceof BungeeCordHandshake.Success);
BungeeCordHandshake.Success success = (BungeeCordHandshake.Success) result;
assertEquals(HOST + "\00education-forwarded-host\00" + payload, success.serverHostname());
assertEquals(IP, success.socketAddressHostname());
assertTrue(result instanceof BungeeCordHandshake.Fail);
}

@Test
public void recognizesFloodgateHandshakeWithoutPropertiesField() {
String payload = "^Floodgate^>encrypted-bedrock-payload";
public void rejectsUnvalidatedFloodgateMarkerWithoutPropertiesField() {
String payload = "^Floodgate^>client-supplied-data";
String handshake = String.join("\00", HOST, payload, IP, UUID_VALUE.toString());

BungeeCordHandshake result = BungeeCordHandshake.decodeAndVerify(handshake, configuredTokenStore());

assertTrue(result instanceof BungeeCordHandshake.Success);
assertEquals("[]", ((BungeeCordHandshake.Success) result).propertiesJson());
assertTrue(result instanceof BungeeCordHandshake.Fail);
}

@Test
public void acceptsFloodgateEvenWhenBungeeGuardTokensAreNotConfigured() {
String payload = "^Floodgate^>encrypted-bedrock-payload";
public void rejectsUnvalidatedFloodgateMarkerWhenTokensAreNotConfigured() {
String payload = "^Floodgate^>client-supplied-data";
String handshake = String.join("\00", HOST, payload, IP, UUID_VALUE.toString(), "[]");

BungeeCordHandshake result = BungeeCordHandshake.decodeAndVerify(handshake, defaultTokenStore());

assertTrue(result instanceof BungeeCordHandshake.Success);
assertTrue(result instanceof BungeeCordHandshake.Fail);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion bungeeguard-sponge/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.10</version>
<version>1.4.11</version>
</parent>

<artifactId>bungeeguard-sponge</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions bungeeguard-universal/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<parent>
<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.10</version>
<version>1.4.11</version>
</parent>

<artifactId>bungeeguard-universal</artifactId>
<version>1.4.10</version>
<version>1.4.11</version>

<build>
<defaultGoal>clean package</defaultGoal>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>me.lucko</groupId>
<artifactId>bungeeguard</artifactId>
<version>1.4.10</version>
<version>1.4.11</version>
<packaging>pom</packaging>

<modules>
Expand Down
Loading