Skip to content

Commit 9239b77

Browse files
committed
Remove user sensitive data from self-diagnostics
1 parent 5d0abe5 commit 9239b77

File tree

1 file changed

+24
-5
lines changed
  • agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init

1 file changed

+24
-5
lines changed

agent/agent-tooling/src/main/java/com/microsoft/applicationinsights/agent/internal/init/FirstEntryPoint.java

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@
3333
import java.lang.management.RuntimeMXBean;
3434
import java.nio.charset.StandardCharsets;
3535
import java.nio.file.Path;
36+
import java.util.Map;
3637
import java.util.Properties;
38+
import java.util.stream.Collectors;
3739
import javax.annotation.Nullable;
3840
import org.slf4j.Logger;
3941
import org.slf4j.LoggerFactory;
@@ -122,7 +124,7 @@ public void init(EarlyInitAgentConfig earlyConfig) {
122124
startupLogger.trace("OS: " + System.getProperty("os.name"));
123125
startupLogger.trace("Classpath: " + System.getProperty("java.class.path"));
124126
startupLogger.trace("Netty versions: " + NettyVersions.extract());
125-
startupLogger.trace("Env: " + System.getenv());
127+
startupLogger.trace("Env: " + findEnvVariables());
126128
startupLogger.trace("System properties: " + findSystemProperties());
127129
}
128130

@@ -138,6 +140,20 @@ public void init(EarlyInitAgentConfig earlyConfig) {
138140
}
139141
}
140142

143+
private static Map<String, String> findEnvVariables() {
144+
Map<String, String> env = System.getenv();
145+
return env.entrySet().stream()
146+
.filter(entry -> !isSensitiveProperty(entry.getKey()))
147+
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
148+
}
149+
150+
private static boolean isSensitiveProperty(String key) {
151+
return key.contains("user")
152+
|| key.contains("password")
153+
|| key.contains("pwd")
154+
|| key.contains("secret");
155+
}
156+
141157
private static void checkTlsConnectionsToVirtualServersEnabled() {
142158
String tlsConnectionsToVirtualServersProp = "jsse.enableSNIExtension";
143159
String propValue = System.getProperty(tlsConnectionsToVirtualServersProp);
@@ -152,11 +168,14 @@ private static String findSystemProperties() {
152168
StringBuilder propsBuilder = new StringBuilder();
153169
properties.forEach(
154170
(key, value) -> {
155-
boolean firstProperty = propsBuilder.length() == 0;
156-
if (!firstProperty) {
157-
propsBuilder.append(", ");
171+
String keyAsString = key.toString();
172+
if (!isSensitiveProperty(keyAsString)) {
173+
boolean firstProperty = propsBuilder.length() == 0;
174+
if (!firstProperty) {
175+
propsBuilder.append(", ");
176+
}
177+
propsBuilder.append("(" + key + "=" + value + ")");
158178
}
159-
propsBuilder.append("(" + key + "=" + value + ")");
160179
});
161180
return propsBuilder.toString();
162181
}

0 commit comments

Comments
 (0)