From 87146ea6c1bb39e5c760cc758a7433471a9df95e Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 27 Oct 2026 08:33:18 -0500 Subject: improve metrics auth --- src/slskd/Program.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index e236886b..e40113e1 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -1168,12 +1168,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; -- cgit v1.2.3 From 648e98b324917681e17195cd6e411ea846a2996c Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 27 Oct 2026 09:12:01 -0500 Subject: fix a few logging bugs --- src/slskd/Program.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/slskd/Program.cs') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index e40113e1..1865453f 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -525,7 +525,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 @@ -1291,7 +1291,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('"'), @@ -1323,11 +1323,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); } }; } -- cgit v1.2.3