Skip to content

Commit

Permalink
Show non-sensitive IPs in all dumps (GeyserMC#2102)
Browse files Browse the repository at this point in the history
IPs such as 0.0.0.0 and 127.0.0.1 will now show in all dumps, regardless of if it's a full dump or not.
  • Loading branch information
Camotoy authored Jun 9, 2021
1 parent 78b7955 commit 1df6e21
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,37 +51,51 @@ public class AsteriskSerializer extends StdSerializer<Object> 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
public JsonSerializer<?> createContextual(SerializerProvider serializerProvider, BeanProperty property) {
Optional<Asterisk> 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");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -184,7 +184,7 @@ public List<CIDRMatcher> getWhitelistedIPsMatchers() {
@JsonIgnoreProperties(ignoreUnknown = true)
public static class RemoteConfiguration implements IRemoteConfiguration {
@Setter
@AsteriskSerializer.Asterisk(sensitive = true)
@AsteriskSerializer.Asterisk(isIp = true)
private String address = "auto";

@Setter
Expand Down

0 comments on commit 1df6e21

Please sign in to comment.