diff --git a/app/src/main/java/io/xpipe/app/beacon/BeaconRequestHandler.java b/app/src/main/java/io/xpipe/app/beacon/BeaconRequestHandler.java index d231c96a0..11ac2de4f 100644 --- a/app/src/main/java/io/xpipe/app/beacon/BeaconRequestHandler.java +++ b/app/src/main/java/io/xpipe/app/beacon/BeaconRequestHandler.java @@ -124,10 +124,9 @@ public class BeaconRequestHandler implements HttpHandler { try { var emptyResponseClass = beaconInterface.getResponseClass().getDeclaredFields().length == 0; if (!emptyResponseClass && response != null) { - TrackEvent.trace("Sending response:\n" + object); - var tree = JacksonMapper.getDefault().valueToTree(response); - TrackEvent.trace("Sending raw response:\n" + tree.toPrettyString()); - var bytes = tree.toPrettyString().getBytes(StandardCharsets.UTF_8); + TrackEvent.trace("Sending response:\n" + response); + TrackEvent.trace("Sending raw response:\n" + JacksonMapper.getCensored().valueToTree(response).toPrettyString()); + var bytes = JacksonMapper.getDefault().valueToTree(response).toPrettyString().getBytes(StandardCharsets.UTF_8); exchange.sendResponseHeaders(200, bytes.length); try (OutputStream os = exchange.getResponseBody()) { os.write(bytes); diff --git a/core/src/main/java/io/xpipe/core/util/JacksonMapper.java b/core/src/main/java/io/xpipe/core/util/JacksonMapper.java index ccb028425..481b5e626 100644 --- a/core/src/main/java/io/xpipe/core/util/JacksonMapper.java +++ b/core/src/main/java/io/xpipe/core/util/JacksonMapper.java @@ -1,13 +1,15 @@ package io.xpipe.core.util; import com.fasterxml.jackson.annotation.JsonAutoDetect; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.Module; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.databind.jsontype.TypeSerializer; +import com.fasterxml.jackson.databind.module.SimpleModule; import lombok.Getter; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.ServiceLoader; @@ -88,4 +90,32 @@ public class JacksonMapper { return INSTANCE; } + + + public static ObjectMapper getCensored() { + if (!JacksonMapper.isInit()) { + return BASE; + } + + var c = INSTANCE.copy(); + c.registerModule(new SimpleModule() { + @Override + public void setupModule(SetupContext context) { + addSerializer(SecretValue.class, new JsonSerializer<>() { + @Override + public void serialize(SecretValue value, JsonGenerator gen, SerializerProvider serializers) throws IOException { + gen.writeString(""); + } + + @Override + public void serializeWithType(SecretValue value, JsonGenerator gen, SerializerProvider serializers, TypeSerializer typeSer) throws + IOException { + gen.writeString(""); + } + }); + super.setupModule(context); + } + }); + return c; + } }