Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
sanitize log entries
Browse files Browse the repository at this point in the history
  • Loading branch information
dkackman committed Nov 25, 2023
1 parent 65f307b commit 2d78ca9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Web2Gateway/G2To3Service.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand All @@ -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);
});

Expand Down
6 changes: 6 additions & 0 deletions Web2Gateway/Utils.cs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 2d78ca9

Please sign in to comment.