]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Redact URLs logged by remote http backend
authorJoel Rosdahl <joel@rosdahl.net>
Fri, 8 Aug 2025 11:06:38 +0000 (13:06 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 8 Aug 2025 11:06:57 +0000 (13:06 +0200)
src/ccache/storage/remote/httpstorage.cpp
src/ccache/storage/storage.cpp
src/ccache/storage/storage.hpp

index dfca496461e197976222d0b6ddd249f914997f59..b361edb82c6951665bf706b7856972ad8f1631d3 100644 (file)
@@ -57,6 +57,7 @@ private:
   enum class Layout : uint8_t { bazel, flat, subdirs };
 
   Url m_url;
+  std::string m_redacted_url;
   std::string m_url_path;
   httplib::Client m_http_client;
   Layout m_layout = Layout::subdirs;
@@ -109,6 +110,7 @@ failure_from_httplib_error(httplib::Error error)
 HttpStorageBackend::HttpStorageBackend(
   const Url& url, const std::vector<Backend::Attribute>& attributes)
   : m_url(url),
+    m_redacted_url(get_redacted_url_str_for_logging(url)),
     m_url_path(get_url_path(url)),
     m_http_client(get_url(url))
 {
@@ -172,7 +174,7 @@ HttpStorageBackend::get(const Hash::Digest& key)
 {
   const auto url_path = get_entry_path(key);
   const auto result = m_http_client.Get(url_path);
-  LOG("GET {}{} -> {}", m_url.str(), url_path, result->status);
+  LOG("GET {}{} -> {}", m_redacted_url, url_path, result->status);
 
   if (result.error() != httplib::Error::Success || !result) {
     LOG("Failed to get {} from http storage: {} ({})",
@@ -199,7 +201,7 @@ HttpStorageBackend::put(const Hash::Digest& key,
 
   if (overwrite == Overwrite::no) {
     const auto result = m_http_client.Head(url_path);
-    LOG("HEAD {}{} -> {}", m_url.str(), url_path, result->status);
+    LOG("HEAD {}{} -> {}", m_redacted_url, url_path, result->status);
 
     if (result.error() != httplib::Error::Success || !result) {
       LOG("Failed to check for {} in http storage: {} ({})",
@@ -223,7 +225,7 @@ HttpStorageBackend::put(const Hash::Digest& key,
                       reinterpret_cast<const char*>(value.data()),
                       value.size(),
                       content_type);
-  LOG("PUT {}{} -> {}", m_url.str(), url_path, result->status);
+  LOG("PUT {}{} -> {}", m_redacted_url, url_path, result->status);
 
   if (result.error() != httplib::Error::Success || !result) {
     LOG("Failed to put {} to http storage: {} ({})",
@@ -248,7 +250,7 @@ HttpStorageBackend::remove(const Hash::Digest& key)
 {
   const auto url_path = get_entry_path(key);
   const auto result = m_http_client.Delete(url_path);
-  LOG("DELETE {}{} -> {}", m_url.str(), url_path, result->status);
+  LOG("DELETE {}{} -> {}", m_redacted_url, url_path, result->status);
 
   if (result.error() != httplib::Error::Success || !result) {
     LOG("Failed to delete {} from http storage: {} ({})",
index cbcb967d10390ca84db200c5edf5b62649c9ef49..06e8df5a4d2332bd321f0b659761acb83253e67d 100644 (file)
@@ -245,6 +245,16 @@ get_storage(const std::string& scheme)
   }
 }
 
+std::string
+get_redacted_url_str_for_logging(const Url& url)
+{
+  Url redacted_url(url);
+  if (!url.user_info().empty()) {
+    redacted_url.user_info(k_redacted_password);
+  }
+  return redacted_url.str();
+}
+
 Storage::Storage(const Config& config)
   : local(config),
     m_config(config)
@@ -318,16 +328,6 @@ Storage::has_remote_storage() const
   return !m_remote_storages.empty();
 }
 
-static std::string
-get_redacted_url_str_for_logging(const Url& url)
-{
-  Url redacted_url(url);
-  if (!url.user_info().empty()) {
-    redacted_url.user_info(k_redacted_password);
-  }
-  return redacted_url.str();
-}
-
 std::string
 Storage::get_remote_storage_config_for_logging() const
 {
index 4525ee910528ad97ced116d9fe3365a3b9e757b5..94ba3e9c714e31dc5f71f4a583dd4de13ee7799a 100644 (file)
@@ -43,6 +43,8 @@ std::vector<std::string> get_features();
 struct RemoteStorageBackendEntry;
 struct RemoteStorageEntry;
 
+std::string get_redacted_url_str_for_logging(const Url& url);
+
 class Storage
 {
 public: