Skip to content

Commit

Permalink
Security fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo committed Jul 10, 2022
1 parent 70c5070 commit 3ba9f8f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<dependency>
<groupId>xyz.leuo</groupId>
<artifactId>Gooey</artifactId>
<version>1.2.2</version>
<version>1.2.3</version>
</dependency>
<!-- MongoDB Driver -->
<dependency>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/github/punishmentsx/ConfigValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ public enum ConfigValues {
REDIS_CHANNEL("DATABASE.REDIS.CHANNEL"),
MONGO_DATABASE("DATABASE.MONGO.DB"),
MONGO_URI("DATABASE.MONGO.URI"),

CONSOLE_NAME("GENERAL.CONSOLE_NAME");

private String path;
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/io/github/punishmentsx/utils/PlayerUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ public static Profile findPlayer(PunishmentsX plugin, String target) {
Profile targetProfile;

if (targetPlayer == null) {
targetProfile = plugin.getProfileManager().find(target, false);
if (plugin.getConfig().getBoolean("GENERAL.ONLINE_MODE")) {
WebPlayer webPlayer = new WebPlayer(target);
targetProfile = plugin.getProfileManager().find(webPlayer.getUuid(), false);
} else {
targetProfile = plugin.getProfileManager().find(target, false);
}
} else {
targetProfile = plugin.getProfileManager().get(targetPlayer.getUniqueId());
}
Expand Down
56 changes: 56 additions & 0 deletions src/main/java/io/github/punishmentsx/utils/WebPlayer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package io.github.punishmentsx.utils;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.Data;

import javax.net.ssl.HttpsURLConnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.UUID;

public @Data class WebPlayer {

private String name;
private UUID uuid;
private boolean valid;

public WebPlayer(String name) {
fromUrl("https://api.mojang.com/users/profiles/minecraft/" + name);
}

private void fromUrl(String s) {
try {

URL url = new URL(s);
HttpsURLConnection c = (HttpsURLConnection) url.openConnection();
c.setRequestMethod("GET");
c.setHostnameVerifier((hostname, session) -> true);
BufferedReader reader = new BufferedReader(new InputStreamReader(c.getInputStream()));

StringBuilder stringBuilder = new StringBuilder();
int cp;
while ((cp = reader.read()) != -1) {
stringBuilder.append((char) cp);
}

String jsonString = stringBuilder.toString();
JsonObject json = new JsonParser().parse(jsonString).getAsJsonObject();
if (json != null) {
this.uuid = UUID.fromString(json.get("id").getAsString().replaceFirst(
"(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)",
"$1-$2-$3-$4-$5"
));
this.name = json.get("name").getAsString();
this.valid = true;
} else {
this.name = null;
this.uuid = null;
this.valid = false;
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ DATABASE:

GENERAL:
SERVER_NAME: "Unspecified" # Example: lobby, kitpvp, factions, etc
ONLINE_MODE: true
CONSOLE_NAME: "CONSOLE"

# REGULAR Example: Tue May 31 23:13:07 GMT 2022
Expand Down

0 comments on commit 3ba9f8f

Please sign in to comment.