Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: For security purposes, remove the output of Capabilities information from the logs. #13710

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now target Java 11+, so it's okay to use Set.of("se:vnc", "se:cdp")


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