diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-10-23 09:28:50 -0500 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-10-23 09:28:50 -0500 |
| commit | 08d846f0f59a1922828504781da0612f3cfde3ab (patch) | |
| tree | 069d5517551be192bdef680191c8cc7424e3a942 /src/slskd/Program.cs | |
| parent | 62cf077ec126089b2a6a1e0c3933167cec4003de (diff) | |
| download | slskd-08d846f0f59a1922828504781da0612f3cfde3ab.tar.gz | |
redact configuration dump when debug is enabled
Diffstat (limited to 'src/slskd/Program.cs')
| -rw-r--r-- | src/slskd/Program.cs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index cdfbbf33..5347e5f5 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -454,7 +454,17 @@ namespace slskd if (OptionsAtStartup.Debug) { - Log.Information($"Configuration:\n{Configuration.GetDebugView()}"); + // redact values for any key matching the name of a property marked [Secret]. keys from YAML may be + // snake or kebab case, so normalize before comparing. this over-redacts, which is fine here + var secretNames = typeof(Options).Assembly.GetTypes() + .Where(t => t == typeof(Options) || (t.FullName?.StartsWith($"{typeof(Options).FullName}+") ?? false)) + .SelectMany(t => t.GetProperties()) + .Where(p => p.GetCustomAttributes(typeof(SecretAttribute), inherit: false).Length > 0) + .Select(p => p.Name.ToLowerInvariant()) + .ToHashSet(); + + Log.Information($"Configuration:\n{Configuration.GetDebugView(context => + secretNames.Contains(context.Key.Replace("_", string.Empty).Replace("-", string.Empty).ToLowerInvariant()) ? "*****" : context.Value)}"); } if (!OptionsAtStartup.TryValidate(out var result)) @@ -465,7 +475,7 @@ namespace slskd } catch (Exception ex) { - Log.Information($"Invalid configuration: {(!OptionsAtStartup.Debug ? ex : ex.Message)}"); + Log.Information($"Invalid configuration: {(OptionsAtStartup.Debug ? ex : ex.Message)}"); return; } |
