Skip to content

Commit e99a482

Browse files
committed
Remove sensitive info from log
1 parent e20325a commit e99a482

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

include/kafka/Properties.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <algorithm>
88
#include <map>
9+
#include <regex>
910
#include <string>
1011

1112

@@ -71,10 +72,17 @@ class Properties
7172

7273
std::string toString() const
7374
{
75+
7476
std::string ret;
7577
std::for_each(_kvMap.cbegin(), _kvMap.cend(),
7678
[&ret](const auto& kv) {
77-
ret.append(ret.empty() ? "" : "|").append(kv.first).append("=").append(kv.second);
79+
const std::string& key = kv.first;
80+
const std::string& value = kv.second;
81+
82+
static const std::regex reSensitiveKey(R"(.+\.password)");
83+
bool isSensitive = std::regex_match(key, reSensitiveKey);
84+
85+
ret.append(ret.empty() ? "" : "|").append(key).append("=").append(isSensitive ? "*" : value);
7886
});
7987
return ret;
8088
}

tests/unit/TestProperties.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,15 @@ TEST(Properties, AdminClientConfig)
8383

8484
EXPECT_EQ("bootstrap.servers=127.0.0.1:9000,127.0.0.1:9001|security.protocol=SASL_PLAINTEXT", props.toString());
8585
}
86+
87+
TEST(Properties, SensitiveProperties)
88+
{
89+
kafka::Properties props
90+
{{
91+
{ "ssl.key.password", "passwordA" },
92+
{ "ssl.keystore.password", "passwordB" },
93+
{ "sasl.password", "passwordC" },
94+
}};
95+
96+
EXPECT_EQ("sasl.password=*|ssl.key.password=*|ssl.keystore.password=*", props.toString());
97+
}

0 commit comments

Comments
 (0)