From 9e81177e44d63501b360b1a246a16ea3faecb548 Mon Sep 17 00:00:00 2001 From: Chesnay Schepler Date: Thu, 22 Feb 2024 18:07:38 +0100 Subject: [PATCH] [FLINK-34499] Configuration#toString hides sensitive values --- .../apache/flink/configuration/Configuration.java | 9 ++++++++- .../flink/configuration/ConfigurationTest.java | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/flink-core/src/main/java/org/apache/flink/configuration/Configuration.java b/flink-core/src/main/java/org/apache/flink/configuration/Configuration.java index d8b06935abc4a..14f714e345f42 100644 --- a/flink-core/src/main/java/org/apache/flink/configuration/Configuration.java +++ b/flink-core/src/main/java/org/apache/flink/configuration/Configuration.java @@ -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; @@ -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(); } } diff --git a/flink-core/src/test/java/org/apache/flink/configuration/ConfigurationTest.java b/flink-core/src/test/java/org/apache/flink/configuration/ConfigurationTest.java index f9caa6e174150..c4a438d78bc3d 100644 --- a/flink-core/src/test/java/org/apache/flink/configuration/ConfigurationTest.java +++ b/flink-core/src/test/java/org/apache/flink/configuration/ConfigurationTest.java @@ -554,6 +554,19 @@ void testMapParserErrorDoesNotLeakSensitiveData() { .doesNotContain("secret_value")); } + @TestTemplate + void testToStringDoesNotLeakSensitiveData() { + ConfigOption> 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);