diff --git a/connector/src/main/java/org/geysermc/connector/common/serializer/AsteriskSerializer.java b/connector/src/main/java/org/geysermc/connector/common/serializer/AsteriskSerializer.java index 0b723817254..8ea6ef220ab 100644 --- a/connector/src/main/java/org/geysermc/connector/common/serializer/AsteriskSerializer.java +++ b/connector/src/main/java/org/geysermc/connector/common/serializer/AsteriskSerializer.java @@ -51,20 +51,25 @@ public class AsteriskSerializer extends StdSerializer implements Context @JsonSerialize(using = AsteriskSerializer.class) public @interface Asterisk { String value() default "***"; - boolean sensitive() default false; + /** + * If true, this value will be shown if {@link #showSensitive} is true, or if the IP is determined to not be a public IP + * + * @return true if this should be analyzed and treated as an IP + */ + boolean isIp() default false; } String asterisk; - boolean sensitive; + boolean isIp; public AsteriskSerializer() { super(Object.class); } - public AsteriskSerializer(String asterisk, boolean sensitive) { + public AsteriskSerializer(String asterisk, boolean isIp) { super(Object.class); this.asterisk = asterisk; - this.sensitive = sensitive; + this.isIp = isIp; } @Override @@ -72,16 +77,25 @@ public JsonSerializer createContextual(SerializerProvider serializerProvider, Optional anno = Optional.ofNullable(property) .map(prop -> prop.getAnnotation(Asterisk.class)); - return new AsteriskSerializer(anno.map(Asterisk::value).orElse(null), anno.map(Asterisk::sensitive).orElse(null)); + return new AsteriskSerializer(anno.map(Asterisk::value).orElse(null), anno.map(Asterisk::isIp).orElse(null)); } @Override public void serialize(Object obj, JsonGenerator gen, SerializerProvider prov) throws IOException { - if (sensitive && showSensitive) { + if (isIp && (showSensitive || !isSensitiveIp((String) obj))) { gen.writeObject(obj); return; } gen.writeString(asterisk); } + + private boolean isSensitiveIp(String ip) { + if (ip.equalsIgnoreCase("localhost") || ip.equalsIgnoreCase("auto")) { + // `auto` should not be shown unless there is an obscure issue with setting the localhost address + return false; + } + + return !ip.isEmpty() && !ip.equals("0.0.0.0") && !ip.equals("127.0.0.1"); + } } diff --git a/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java b/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java index 5840561c622..dbafcf715f7 100644 --- a/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java +++ b/connector/src/main/java/org/geysermc/connector/configuration/GeyserJacksonConfiguration.java @@ -134,7 +134,7 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration @Getter @JsonIgnoreProperties(ignoreUnknown = true) public static class BedrockConfiguration implements IBedrockConfiguration { - @AsteriskSerializer.Asterisk(sensitive = true) + @AsteriskSerializer.Asterisk(isIp = true) private String address = "0.0.0.0"; @Setter @@ -184,7 +184,7 @@ public List getWhitelistedIPsMatchers() { @JsonIgnoreProperties(ignoreUnknown = true) public static class RemoteConfiguration implements IRemoteConfiguration { @Setter - @AsteriskSerializer.Asterisk(sensitive = true) + @AsteriskSerializer.Asterisk(isIp = true) private String address = "auto"; @Setter