Skip to content

Commit

Permalink
fix(spigot): detect velocity modern forwarding for proxy warning (#367)
Browse files Browse the repository at this point in the history
Fixes #328
  • Loading branch information
diogotcorreia authored Dec 18, 2023
1 parent 2c0fbdb commit aba7a9b
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public void onEnable() {
}

if (getConfig().isBungeecord()) {
if (!isSpigotProxyMode()) {
if (!isSpigotProxyMode() && !isPaperProxyMode()) {
getLogger().logError("DANGER! DANGER! DANGER!");
getLogger().logError("Proxy mode is enabled on Triton but disabled on Spigot!");
getLogger().logError("A malicious player can run ANY command as the server.");
Expand Down Expand Up @@ -302,4 +302,27 @@ public boolean isSpigotProxyMode() {
return false;
}
}

/**
* Use reflection to check if this Paper server has velocity modern forwarding enabled on paper-global.yml.
* This is used to show a warning if Paper is in proxy mode, but the server is not.
*
* @return Whether this Spigot server has velocity forwarding enabled on paper-global.yml.
*/
public boolean isPaperProxyMode() {
try {
Class<?> paperConfigClass = Class.forName("io.papermc.paper.configuration.GlobalConfiguration");

Object instance = paperConfigClass.getMethod("get").invoke(null);
Object proxies = instance.getClass().getField("proxies").get(instance);
Object velocity = proxies.getClass().getField("velocity").get(proxies);
Object velocityEnabled = velocity.getClass().getField("enabled").get(velocity);
if (velocityEnabled == null) {
return false;
}
return (boolean) velocityEnabled;
} catch (Exception e) {
return false;
}
}
}

0 comments on commit aba7a9b

Please sign in to comment.