From 2d78ca9f8a8e24211e2ec85fa15c083717fa938a Mon Sep 17 00:00:00 2001 From: Don Kackman Date: Sat, 25 Nov 2023 14:32:30 -0600 Subject: [PATCH] sanitize log entries --- Web2Gateway/G2To3Service.cs | 4 ++-- Web2Gateway/Utils.cs | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Web2Gateway/G2To3Service.cs b/Web2Gateway/G2To3Service.cs index 6141119..5085bf3 100644 --- a/Web2Gateway/G2To3Service.cs +++ b/Web2Gateway/G2To3Service.cs @@ -37,7 +37,7 @@ public WellKnown GetWellKnown() var keys = await _memoryCache.GetOrCreateAsync($"{storeId}", async entry => { entry.SlidingExpiration = TimeSpan.FromMinutes(15); - _logger.LogInformation("Getting keys for {StoreId}", storeId); + _logger.LogInformation("Getting keys for {StoreId}", storeId.SanitizeForLog()); return await _dataLayer.GetKeys(storeId, null, cancellationToken); }); @@ -56,7 +56,7 @@ public WellKnown GetWellKnown() var value = await _memoryCache.GetOrCreateAsync($"{storeId}-{key}", async entry => { entry.SlidingExpiration = TimeSpan.FromMinutes(15); - _logger.LogInformation("Getting value for {StoreId} {Key}", storeId, key); + _logger.LogInformation("Getting value for {StoreId} {Key}", storeId.SanitizeForLog(), key.SanitizeForLog()); return await _dataLayer.GetValue(storeId, key, null, cancellationToken); }); diff --git a/Web2Gateway/Utils.cs b/Web2Gateway/Utils.cs index 54e57c2..8c561f9 100644 --- a/Web2Gateway/Utils.cs +++ b/Web2Gateway/Utils.cs @@ -1,9 +1,15 @@ using System.Text.Json; +using System.Text.RegularExpressions; namespace Web2Gateway; internal static class Utils { + public static string SanitizeForLog(this string input) + { + return Regex.Replace(input, @"\W", "_"); + } + public static bool IsBase64Image(string data) { return data.StartsWith("data:image", StringComparison.OrdinalIgnoreCase);