Skip to content

Commit

Permalink
[FLINK-34499] Configuration#toString hides sensitive values
Browse files Browse the repository at this point in the history
  • Loading branch information
zentol authored and XComp committed Feb 29, 2024
1 parent 8bb4457 commit 9e81177
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.function.BiFunction;
import java.util.stream.Collectors;

import static org.apache.flink.configuration.ConfigurationUtils.canBePrefixMap;
import static org.apache.flink.configuration.ConfigurationUtils.containsPrefixMap;
Expand Down Expand Up @@ -1126,6 +1127,12 @@ public boolean equals(Object obj) {

@Override
public String toString() {
return this.confData.toString();
return ConfigurationUtils.hideSensitiveValues(
this.confData.entrySet().stream()
.collect(
Collectors.toMap(
Map.Entry::getKey,
entry -> entry.getValue().toString())))
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,19 @@ void testMapParserErrorDoesNotLeakSensitiveData() {
.doesNotContain("secret_value"));
}

@TestTemplate
void testToStringDoesNotLeakSensitiveData() {
ConfigOption<Map<String, String>> secret =
ConfigOptions.key("secret").mapType().noDefaultValue();

Assertions.assertThat(GlobalConfiguration.isSensitive(secret.key())).isTrue();

final Configuration cfg = new Configuration(standardYaml);
cfg.setString(secret.key(), "secret_value");

assertThat(cfg.toString()).doesNotContain("secret_value");
}

@TestTemplate
void testGetWithOverrideDefault() {
final Configuration conf = new Configuration(standardYaml);
Expand Down

0 comments on commit 9e81177

Please sign in to comment.