Mirror von
https://github.com/GeyserMC/Geyser.git
synchronisiert 2024-12-26 00:00:41 +01:00
Show non-sensitive IPs in all dumps (#2102)
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.
Dieser Commit ist enthalten in:
Ursprung
78b7955111
Commit
1df6e2151d
@ -51,20 +51,25 @@ public class AsteriskSerializer extends StdSerializer<Object> implements Context
|
|||||||
@JsonSerialize(using = AsteriskSerializer.class)
|
@JsonSerialize(using = AsteriskSerializer.class)
|
||||||
public @interface Asterisk {
|
public @interface Asterisk {
|
||||||
String value() default "***";
|
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;
|
String asterisk;
|
||||||
boolean sensitive;
|
boolean isIp;
|
||||||
|
|
||||||
public AsteriskSerializer() {
|
public AsteriskSerializer() {
|
||||||
super(Object.class);
|
super(Object.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public AsteriskSerializer(String asterisk, boolean sensitive) {
|
public AsteriskSerializer(String asterisk, boolean isIp) {
|
||||||
super(Object.class);
|
super(Object.class);
|
||||||
this.asterisk = asterisk;
|
this.asterisk = asterisk;
|
||||||
this.sensitive = sensitive;
|
this.isIp = isIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -72,16 +77,25 @@ public class AsteriskSerializer extends StdSerializer<Object> implements Context
|
|||||||
Optional<Asterisk> anno = Optional.ofNullable(property)
|
Optional<Asterisk> anno = Optional.ofNullable(property)
|
||||||
.map(prop -> prop.getAnnotation(Asterisk.class));
|
.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
|
@Override
|
||||||
public void serialize(Object obj, JsonGenerator gen, SerializerProvider prov) throws IOException {
|
public void serialize(Object obj, JsonGenerator gen, SerializerProvider prov) throws IOException {
|
||||||
if (sensitive && showSensitive) {
|
if (isIp && (showSensitive || !isSensitiveIp((String) obj))) {
|
||||||
gen.writeObject(obj);
|
gen.writeObject(obj);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
gen.writeString(asterisk);
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
|
|||||||
@Getter
|
@Getter
|
||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public static class BedrockConfiguration implements IBedrockConfiguration {
|
public static class BedrockConfiguration implements IBedrockConfiguration {
|
||||||
@AsteriskSerializer.Asterisk(sensitive = true)
|
@AsteriskSerializer.Asterisk(isIp = true)
|
||||||
private String address = "0.0.0.0";
|
private String address = "0.0.0.0";
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
@ -184,7 +184,7 @@ public abstract class GeyserJacksonConfiguration implements GeyserConfiguration
|
|||||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
public static class RemoteConfiguration implements IRemoteConfiguration {
|
public static class RemoteConfiguration implements IRemoteConfiguration {
|
||||||
@Setter
|
@Setter
|
||||||
@AsteriskSerializer.Asterisk(sensitive = true)
|
@AsteriskSerializer.Asterisk(isIp = true)
|
||||||
private String address = "auto";
|
private String address = "auto";
|
||||||
|
|
||||||
@Setter
|
@Setter
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren