diff --git a/src/main/java/org/qubership/integration/platform/engine/service/debugger/CamelDebugger.java b/src/main/java/org/qubership/integration/platform/engine/service/debugger/CamelDebugger.java index 46417804..9e056838 100644 --- a/src/main/java/org/qubership/integration/platform/engine/service/debugger/CamelDebugger.java +++ b/src/main/java/org/qubership/integration/platform/engine/service/debugger/CamelDebugger.java @@ -181,7 +181,7 @@ public boolean beforeProcess(Exchange exchange, Processor processor, NamedNode d ChainElementType chainElementType = ChainElementType.fromString( dbgProperties.getElementProperty(nodeId).get(ChainProperties.ELEMENT_TYPE)); - Map headersForLogging = Collections.emptyMap(); + Map headersForLogging = new HashMap<>(); Map exchangePropertiesForLogging = Collections.emptyMap(); String bodyForLogging = null; diff --git a/src/main/java/org/qubership/integration/platform/engine/service/debugger/logging/ChainLogger.java b/src/main/java/org/qubership/integration/platform/engine/service/debugger/logging/ChainLogger.java index 19325d82..dd324a96 100644 --- a/src/main/java/org/qubership/integration/platform/engine/service/debugger/logging/ChainLogger.java +++ b/src/main/java/org/qubership/integration/platform/engine/service/debugger/logging/ChainLogger.java @@ -49,6 +49,8 @@ import java.util.Map; import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.Nullable; @Slf4j @@ -60,6 +62,8 @@ public class ChainLogger { public static final String MDC_TRACE_ID = "trace_id"; public static final String MDC_SNAP_ID = "span_id"; + private static final Set SENSITIVE_KEYS = Set.of("username", "password"); + private final TracingService tracingService; private final Optional originatingBusinessIdProvider; @@ -103,6 +107,8 @@ public void logBeforeProcess( String nodeId ) { bodyForLogging = DebuggerUtils.chooseLogPayload(exchange, bodyForLogging, dbgProperties); + exchangePropertiesForLogging = filterExchangeProperties(exchangePropertiesForLogging); + headersForLogging.replace("Authorization", CamelConstants.MASKING_TEMPLATE); if (dbgProperties.getRuntimeProperties(exchange).getLogLoggingLevel().isInfoLevel()) { ChainElementType type = ChainElementType.fromString( dbgProperties.getElementProperty(nodeId).get( @@ -514,4 +520,18 @@ private String constructExtendedLogMessage(Long responseTime, String direction) return String.format("[responseTime=%-4s] [direction=%-8s]", responseTimeStr, direction); } + + public Map filterExchangeProperties(Map props) { + + return props.entrySet().stream() + .filter(entry -> { + String key = entry.getKey(); + if (key == null) { + return false; + } + String lowerKey = key.toLowerCase(); + return SENSITIVE_KEYS.stream().noneMatch(lowerKey::contains); + }) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } } diff --git a/src/test/java/org/qubership/integration/platform/engine/service/debugger/logging/ChainLoggerTest.java b/src/test/java/org/qubership/integration/platform/engine/service/debugger/logging/ChainLoggerTest.java new file mode 100644 index 00000000..3d3296ac --- /dev/null +++ b/src/test/java/org/qubership/integration/platform/engine/service/debugger/logging/ChainLoggerTest.java @@ -0,0 +1,34 @@ +package org.qubership.integration.platform.engine.service.debugger.logging; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.qubership.integration.platform.engine.model.SessionElementProperty; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ChainLoggerTest { + + private ChainLogger chainLogger; + + @BeforeEach + void setUp() { + chainLogger = new ChainLogger(null, Optional.empty()); + } + + @Test + void shouldFilterSensitiveExchangeProperties() { + Map props = new HashMap<>(); + props.put("dbaas_password", new SessionElementProperty("java.lang.String", "secret")); + props.put("dbaas_username", new SessionElementProperty("java.lang.String", "secret")); + props.put("namespace", new SessionElementProperty("java.lang.String", "qa08")); + Map filteredExchangeProperties = chainLogger.filterExchangeProperties(props); + assertFalse(filteredExchangeProperties.containsKey("dbaas_password")); + assertFalse(filteredExchangeProperties.containsKey("dbaas_username")); + assertTrue(filteredExchangeProperties.containsKey("namespace")); + } +}