Skip to content

Commit

Permalink
fix: Sensitive information is hidden by default.
Browse files Browse the repository at this point in the history
Fixes #13648
  • Loading branch information
zhangwt-cn committed Mar 21, 2024
1 parent 4c279c7 commit 3681387
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions java/src/org/openqa/selenium/SharedCapabilitiesMethods.java
Expand Up @@ -20,8 +20,10 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.openqa.selenium.logging.LogLevelMapping;
Expand All @@ -31,6 +33,16 @@ class SharedCapabilitiesMethods {

private static final String[] EMPTY_ARRAY = new String[0];

private static Boolean PRIVACY_MODE = true;

private static final Set<String> PRIVACY_KEYS;

static {
PRIVACY_KEYS = new HashSet<>();
PRIVACY_KEYS.add("se:vnc");
PRIVACY_KEYS.add("se:cdp");
}

private SharedCapabilitiesMethods() {
// Utility class
}
Expand All @@ -57,6 +69,10 @@ static boolean equals(Capabilities left, Capabilities right) {
}

static void setCapability(Map<String, Object> caps, String key, Object value) {
if ("privacyMode".equals(key) && value instanceof Boolean) {
PRIVACY_MODE = (Boolean) value;
}

if ("loggingPrefs".equals(key) && value instanceof Map) {
LoggingPreferences prefs = new LoggingPreferences();
@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -111,9 +127,13 @@ private static String abbreviate(Map<Object, String> seen, Object stringify) {
.entrySet().stream()
.sorted(Comparator.comparing(entry -> String.valueOf(entry.getKey())))
.map(
entry ->
String.format(
"%s: %s", entry.getKey(), abbreviate(seen, entry.getValue())))
entry -> {
if (PRIVACY_MODE && PRIVACY_KEYS.contains(String.valueOf(entry.getKey()))) {
return String.format("%s: %s", entry.getKey(), "********");
}
return String.format(
"%s: %s", entry.getKey(), abbreviate(seen, entry.getValue()));
})
.collect(Collectors.joining(", ")));
value.append("}");
} else {
Expand Down

0 comments on commit 3681387

Please sign in to comment.