diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-11-08 10:15:14 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-08 10:15:14 -0600 |
| commit | 169bb8a3c0098599a617d8553e93c694bd813795 (patch) | |
| tree | 4d825302717fc76d543b6a24469ad23a605cd5c8 /src/slskd/Program.cs | |
| parent | 4eaa2b13e2da250d7b89073a15e9f1e077661fd7 (diff) | |
| parent | cefdcd02e28b1f02f546002fdd475de4fa03e839 (diff) | |
| download | slskd-169bb8a3c0098599a617d8553e93c694bd813795.tar.gz | |
Merge branch 'master' into dependabot/npm_and_yarn/src/web/follow-redirects-1.16.2
Diffstat (limited to 'src/slskd/Program.cs')
| -rw-r--r-- | src/slskd/Program.cs | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 372dc998..879f76b7 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -535,7 +535,7 @@ namespace slskd if (!string.IsNullOrEmpty(OptionsAtStartup.Logger.Loki)) { - Log.Information("Forwarding logs to Grafana Loki instance at {LoggerLokiUrl}", OptionsAtStartup.Logger.Loki); + Log.Information("Forwarding logs to Grafana Loki"); } // bootstrap the ASP.NET application @@ -1178,12 +1178,14 @@ namespace slskd if (!options.Authentication.Disabled) { var auth = context.Request.Headers["Authorization"].FirstOrDefault(); - var providedCreds = auth?.Split(' ').Last(); + var providedCreds = auth?.Split(' ').Last() ?? string.Empty; var validCreds = Convert.ToBase64String(Encoding.UTF8.GetBytes($"{options.Authentication.Username}:{options.Authentication.Password}")); + // use paranoid FixedTimeEquals to protect against time attacks if (string.IsNullOrEmpty(auth) || - !auth.StartsWith("Basic", StringComparison.InvariantCultureIgnoreCase) || - !string.Equals(providedCreds, validCreds, StringComparison.InvariantCultureIgnoreCase)) + !auth.StartsWith("Basic ", StringComparison.InvariantCultureIgnoreCase) || + string.IsNullOrEmpty(providedCreds) || + !System.Security.Cryptography.CryptographicOperations.FixedTimeEquals(Encoding.UTF8.GetBytes(providedCreds), Encoding.UTF8.GetBytes(validCreds))) { context.Response.StatusCode = (int)HttpStatusCode.Unauthorized; return; @@ -1299,7 +1301,7 @@ namespace slskd var record = new LogRecord() { Timestamp = logEvent.Timestamp.LocalDateTime, - Context = logEvent.Properties["SourceContext"].ToString().TrimStart('"').TrimEnd('"'), + Context = logEvent.Properties.TryGetValue("SourceContext", out var sourceContext) ? sourceContext.ToString().TrimStart('"').TrimEnd('"') : null, SubContext = logEvent.Properties.ContainsKey("SubContext") ? logEvent.Properties["SubContext"].ToString().TrimStart('"').TrimEnd('"') : null, Level = logEvent.Level.ToString(), Message = message.TrimStart('"').TrimEnd('"'), @@ -1331,11 +1333,11 @@ namespace slskd if (e.IsTerminating) { - Serilog.Log.Logger.Fatal(exception, "Unhandled fatal exception: {Message}", e.IsTerminating); + Serilog.Log.Logger.Fatal(exception, "Unhandled fatal exception: {Message}", exception?.Message); } else { - Serilog.Log.Logger.Error(exception, "Unhandled exception: {Message}", exception.Message); + Serilog.Log.Logger.Error(exception, "Unhandled exception: {Message}", exception?.Message); } }; } |
