log: increase privacy by not login weather urls and results

This commit is contained in:
Lemmy
2026-05-10 00:38:57 -04:00
parent 0e5c3ee882
commit acfe9d5109
2 changed files with 26 additions and 16 deletions
+22 -10
View File
@@ -19,6 +19,17 @@ namespace {
return std::chrono::duration<float, std::milli>(std::chrono::steady_clock::now() - start).count();
}
std::string urlForLog(std::string_view url) {
const std::size_t redactedPos = url.find_first_of("?#");
if (redactedPos != std::string_view::npos) {
const char suffix = url[redactedPos] == '?' ? '?' : '#';
return std::string(url.substr(0, redactedPos)) + suffix +
(suffix == '?' ? "<query redacted>" : "<fragment redacted>");
}
return std::string(url);
}
void deferFailure(HttpClient::CompletionCallback cb) {
if (!cb) {
return;
@@ -80,7 +91,7 @@ bool HttpClient::hasActiveTransfers() const { return !m_transfers.empty() || !m_
void HttpClient::download(std::string_view url, const std::filesystem::path& destPath, CompletionCallback cb) {
if (m_offlineMode) {
kLog.warn("download skipped in offline mode url={}", url);
kLog.warn("download skipped in offline mode url={}", urlForLog(url));
deferFailure(std::move(cb));
return;
}
@@ -98,7 +109,7 @@ void HttpClient::download(std::string_view url, const std::filesystem::path& des
FILE* f = std::fopen(tempPath.c_str(), "wb");
if (f == nullptr) {
kLog.warn("download failed to open temp file {} for url={}", tempPath.string(), url);
kLog.warn("download failed to open temp file {} for url={}", tempPath.string(), urlForLog(url));
deferFailure(std::move(cb));
return;
}
@@ -107,7 +118,7 @@ void HttpClient::download(std::string_view url, const std::filesystem::path& des
if (easy == nullptr) {
std::fclose(f);
std::filesystem::remove(tempPath);
kLog.warn("download failed to create curl handle url={}", url);
kLog.warn("download failed to create curl handle url={}", urlForLog(url));
deferFailure(std::move(cb));
return;
}
@@ -138,7 +149,7 @@ void HttpClient::download(std::string_view url, const std::filesystem::path& des
std::fclose(failedTransfer.file);
}
std::filesystem::remove(failedTransfer.tempPath);
kLog.warn("download failed to add curl handle url={} error={}", urlStr, curl_multi_strerror(addResult));
kLog.warn("download failed to add curl handle url={} error={}", urlForLog(urlStr), curl_multi_strerror(addResult));
deferFailures(std::move(failedTransfer.callbacks));
return;
}
@@ -148,14 +159,14 @@ void HttpClient::download(std::string_view url, const std::filesystem::path& des
void HttpClient::post(std::string_view url, std::string body, std::string_view contentType, CompletionCallback cb) {
if (m_offlineMode) {
kLog.warn("post skipped in offline mode url={}", url);
kLog.warn("post skipped in offline mode url={}", urlForLog(url));
deferFailure(std::move(cb));
return;
}
CURL* easy = curl_easy_init();
if (easy == nullptr) {
kLog.warn("post failed to create curl handle url={}", url);
kLog.warn("post failed to create curl handle url={}", urlForLog(url));
deferFailure(std::move(cb));
return;
}
@@ -190,7 +201,7 @@ void HttpClient::post(std::string_view url, std::string body, std::string_view c
if (failedPost.headers != nullptr) {
curl_slist_free_all(failedPost.headers);
}
kLog.warn("post failed to add curl handle url={} error={}", urlStr, curl_multi_strerror(addResult));
kLog.warn("post failed to add curl handle url={} error={}", urlForLog(urlStr), curl_multi_strerror(addResult));
deferFailure(std::move(failedPost.callback));
return;
}
@@ -320,8 +331,8 @@ void HttpClient::finishTransfer(CURL* easy, CURLcode result) {
}
} else {
const char* detail = transfer.errorBuffer[0] != '\0' ? transfer.errorBuffer.data() : curl_easy_strerror(result);
kLog.warn("download failed url={} curl={} http={} error={}", transfer.url, static_cast<int>(result), responseCode,
detail);
kLog.warn("download failed url={} curl={} http={} error={}", urlForLog(transfer.url), static_cast<int>(result),
responseCode, detail);
std::filesystem::remove(transfer.tempPath);
}
@@ -354,7 +365,8 @@ void HttpClient::finishPostTransfer(CURL* easy, CURLcode result) {
const bool success = result == CURLE_OK;
if (!success) {
const char* detail = post.errorBuffer[0] != '\0' ? post.errorBuffer.data() : curl_easy_strerror(result);
kLog.warn("post failed url={} curl={} http={} error={}", post.url, static_cast<int>(result), responseCode, detail);
kLog.warn("post failed url={} curl={} http={} error={}", urlForLog(post.url), static_cast<int>(result),
responseCode, detail);
}
if (post.callback) {
+4 -6
View File
@@ -466,8 +466,7 @@ void WeatherService::handleLocationResponse(const std::filesystem::path& path, b
m_error = autoLocated ? i18n::tr("weather.errors.ip-geolocation-failed")
: i18n::tr("weather.errors.address-lookup-failed");
if (canFetchWeatherAfterLocationFailure(autoLocated)) {
kLog.warn("{}; fetching weather using last resolved location {} ({}, {})", m_error, m_resolvedLocationName,
m_resolvedLatitude, m_resolvedLongitude);
kLog.warn("{}; fetching weather using last resolved weather location", m_error);
startWeatherFetch();
return;
}
@@ -495,14 +494,13 @@ void WeatherService::handleLocationResponse(const std::filesystem::path& path, b
m_resolvedLocationName = autoLocated ? i18n::tr("weather.locations.current") : m_activeConfig.address;
}
kLog.info("location resolved: {} ({}, {})", m_resolvedLocationName, m_resolvedLatitude, m_resolvedLongitude);
kLog.info("weather location resolved");
startWeatherFetch();
} catch (const std::exception& e) {
m_loading = false;
m_error = autoLocated ? i18n::tr("weather.errors.parse-ip-geolocation") : i18n::tr("weather.errors.parse-geocode");
if (canFetchWeatherAfterLocationFailure(autoLocated)) {
kLog.warn("{}: {}; fetching weather using last resolved location {} ({}, {})", m_error, e.what(),
m_resolvedLocationName, m_resolvedLatitude, m_resolvedLongitude);
kLog.warn("{}: {}; fetching weather using last resolved weather location", m_error, e.what());
startWeatherFetch();
return;
}
@@ -727,7 +725,7 @@ void WeatherService::loadCache() {
m_locationResolved = true;
m_nextRefreshAt = m_snapshot.fetchedAt + std::chrono::minutes(std::max(5, m_activeConfig.refreshMinutes));
kLog.info("loaded cached weather for {} from {}", m_snapshot.locationName, path.string());
kLog.info("loaded cached weather data");
} catch (const std::exception& e) {
kLog.warn("failed to load weather cache: {}", e.what());
}