From 7502bf6885ea6d89b7a203927e93d6b6aff9e070 Mon Sep 17 00:00:00 2001 From: emeric Date: Fri, 9 May 2025 12:50:56 +0200 Subject: [PATCH] Redacted apiKey values --- src/libs/subsonic/impl/SubsonicResource.cpp | 22 ++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/libs/subsonic/impl/SubsonicResource.cpp b/src/libs/subsonic/impl/SubsonicResource.cpp index c041406d..5fc5ad54 100644 --- a/src/libs/subsonic/impl/SubsonicResource.cpp +++ b/src/libs/subsonic/impl/SubsonicResource.cpp @@ -87,27 +87,31 @@ namespace lms::api::subsonic std::string parameterMapToDebugString(const Wt::Http::ParameterMap& parameterMap) { - auto censorValue = [](const std::string& type, const std::string& value) -> std::string { - if (type == "p" || type == "password") - return "*REDACTED*"; + constexpr std::string_view redactedStr{ "*REDACTED*" }; + auto redactValueIfNeeded = [redactedStr](const std::string& type, const std::string& value) -> std::string_view { + if (type == "p" || type == "password" || type == "apiKey") + return redactedStr; return value; }; std::string res; - for (const auto& params : parameterMap) + for (const auto& [type, values] : parameterMap) { - res += "{" + params.first + "="; - if (params.second.size() == 1) + res += "{" + type + "="; + if (values.size() == 1) { - res += censorValue(params.first, params.second.front()); + res += redactValueIfNeeded(type, values.front()); } else { res += "{"; - for (const std::string& param : params.second) - res += censorValue(params.first, param) + ","; + for (const std::string& value : values) + { + res += redactValueIfNeeded(type, value); + res += ','; + } res += "}"; } res += "}, ";