From 865fcbc4fed85e9eac58125092838f08dbd55430 Mon Sep 17 00:00:00 2001 From: xovi Date: Wed, 26 Nov 2025 15:23:43 +0100 Subject: Added configurable ip address for the Web GUI (useful for ipv6 only users) --- src/slskd/Core/Options.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 254adcab..ab08be04 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1832,6 +1832,16 @@ namespace slskd [RequiresRestart] public int Port { get; init; } = 5030; + /// + /// Gets the IP address on which to listen for HTTP requests. + /// + [Argument(default, "http-listen-ip-address")] + [EnvironmentVariable("HTTP_LISTEN_IP_ADDRESS")] + [Description("IP address on which to listen for HTTP requests")] + [IPAddress] + [RequiresRestart] + public string ListenIpAddress { get; init; } = "0.0.0.0"; + /// /// Gets the HTTP listen unix domain socket (UDS) path. /// @@ -2032,7 +2042,17 @@ namespace slskd [Range(1, 65535)] [RequiresRestart] public int Port { get; init; } = 5031; - + + /// + /// Gets the IP address on which to listen for HTTPS requests. + /// + [Argument(default, "https-listen-ip-address")] + [EnvironmentVariable("HTTPS_LISTEN_IP_ADDRESS")] + [Description("IP address on which to listen for HTTPS requests")] + [IPAddress] + [RequiresRestart] + public string ListenIpAddress { get; init; } = "0.0.0.0"; + /// /// Gets a value indicating whether HTTP requests should be redirected to HTTPS. /// -- cgit v1.2.3 From ea0d7e74ada936d4212129a58bd3a29e09ba8c3e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 7 Dec 2025 00:08:34 +0000 Subject: Add validation check for blacklist file when enabled Co-authored-by: jpdillingham <17145758+jpdillingham@users.noreply.github.com> --- src/slskd/Core/Options.cs | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 254adcab..b93ac5e2 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1252,6 +1252,12 @@ namespace slskd return results; } + if (string.IsNullOrWhiteSpace(File)) + { + results.Add(new ValidationResult("The Enabled field is true, but no File has been specified")); + return results; + } + // loading/validating the entire list will be costly on low spec systems // just make sure that we can detect a valid format and leave it at that // if there's a problem with any of the entries, the load will fail and -- cgit v1.2.3 From 88b42219f4bd707713a90656d9177458a447005b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 7 Dec 2025 00:09:59 +0000 Subject: Add period to validation message for consistency Co-authored-by: jpdillingham <17145758+jpdillingham@users.noreply.github.com> --- src/slskd/Core/Options.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index b93ac5e2..76dcd45c 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1254,7 +1254,7 @@ namespace slskd if (string.IsNullOrWhiteSpace(File)) { - results.Add(new ValidationResult("The Enabled field is true, but no File has been specified")); + results.Add(new ValidationResult("The Enabled field is true, but no File has been specified.")); return results; } -- cgit v1.2.3 From 35a8023360d444021167022970bff1a85ed4e9b7 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 9 Dec 2025 19:28:21 -0600 Subject: update options to allow comma separated lists --- src/slskd/Core/Options.cs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index d3e302a5..afeb1797 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1839,14 +1839,14 @@ namespace slskd public int Port { get; init; } = 5030; /// - /// Gets the IP address on which to listen for HTTP requests. + /// Gets the comma separated list of IPv4 or IPv6 IP addresses on which to listen for HTTP requests. /// - [Argument(default, "http-listen-ip-address")] - [EnvironmentVariable("HTTP_LISTEN_IP_ADDRESS")] - [Description("IP address on which to listen for HTTP requests")] + [Argument(default, "http-ip-address")] + [EnvironmentVariable("HTTP_IP_ADDRESS")] + [Description("IP addresses on which to listen for HTTP requests")] [IPAddress] [RequiresRestart] - public string ListenIpAddress { get; init; } = "0.0.0.0"; + public string IpAddress { get; init; } /// /// Gets the HTTP listen unix domain socket (UDS) path. @@ -2048,17 +2048,17 @@ namespace slskd [Range(1, 65535)] [RequiresRestart] public int Port { get; init; } = 5031; - + /// - /// Gets the IP address on which to listen for HTTPS requests. + /// Gets the comma separated list of IPv4 or IPv6 IP addresses on which to listen for HTTPS requests. /// - [Argument(default, "https-listen-ip-address")] - [EnvironmentVariable("HTTPS_LISTEN_IP_ADDRESS")] - [Description("IP address on which to listen for HTTPS requests")] - [IPAddress] + [Argument(default, "https-ip-address")] + [EnvironmentVariable("HTTPS_IP_ADDRESS")] + [Description("IP addresses on which to listen for HTTPS requests")] + [IPAddress(allowCommaSeparatedValues: true)] [RequiresRestart] - public string ListenIpAddress { get; init; } = "0.0.0.0"; - + public string IpAddress { get; init; } + /// /// Gets a value indicating whether HTTP requests should be redirected to HTTPS. /// -- cgit v1.2.3 From c026b58c435372b7042d5a1ddf911dd4429ba993 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 9 Dec 2025 19:28:43 -0600 Subject: allow lists --- src/slskd/Core/Options.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index afeb1797..1739f5fb 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1844,7 +1844,7 @@ namespace slskd [Argument(default, "http-ip-address")] [EnvironmentVariable("HTTP_IP_ADDRESS")] [Description("IP addresses on which to listen for HTTP requests")] - [IPAddress] + [IPAddress(allowCommaSeparatedValues: true)] [RequiresRestart] public string IpAddress { get; init; } -- cgit v1.2.3 From 08b20cd73d1fed6100649d3d0f4886a1c4362823 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 12 Dec 2025 09:34:01 -0600 Subject: remove single character cli args for envars and cert/secret gen --- src/slskd/Core/Options.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 1739f5fb..cca7e01d 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -115,7 +115,7 @@ namespace slskd /// /// Gets a value indicating whether to display a list of configuration environment variables. /// - [Argument('e', "envars")] + [Argument(default, "envars")] [Description("display environment variables")] [Obsolete("Used only for documentation; see Program for actual implementation")] [JsonIgnore] @@ -125,7 +125,7 @@ namespace slskd /// /// Gets a value indicating whether to generate an X509 certificate and password. /// - [Argument('g', "generate-cert")] + [Argument(default, "generate-cert")] [Description("generate X509 certificate and password for HTTPS")] [Obsolete("Used only for documentation; see Program for actual implementation")] [JsonIgnore] @@ -135,7 +135,7 @@ namespace slskd /// /// Gets a value indicating whether to generate a random secret. /// - [Argument('k', "generate-secret")] + [Argument(default, "generate-secret")] [Description("generate random secret of the specified length")] [Obsolete("Used only for documentation; see Program for actual implementation")] [JsonIgnore] -- cgit v1.2.3 From eaab0b09e0e23ca661163fe7da6ccbab64a24cc8 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 12 Dec 2025 19:10:36 -0600 Subject: add validation of admin api key --- src/slskd/Core/Options.cs | 69 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index cca7e01d..fc367578 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1903,7 +1903,7 @@ namespace slskd /// /// Authentication options. /// - public class WebAuthenticationOptions + public class WebAuthenticationOptions : IValidatableObject { /// /// Gets a value indicating whether authentication should be disabled. @@ -1940,12 +1940,79 @@ namespace slskd [RequiresRestart] public JwtOptions Jwt { get; init; } = new JwtOptions(); + /// + /// Gets the primary API key. Defaults to 'Administrator' role and CIDR '0.0.0.0/0,::/0'. + /// role and CIDR can be supplied by prefixing the key with 'role=[role];cidr=[cidrs];[key]'. + /// + [Description("Administrative API key value")] + [Secret] + [RequiresRestart] + public string ApiKey { get; init; } + /// /// Gets API keys. /// [Validate] public Dictionary ApiKeys { get; init; } = new Dictionary(); + public IEnumerable Validate(ValidationContext validationContext) + { + var results = new List(); + + if (string.IsNullOrWhiteSpace(ApiKey)) + { + return results; + } + + var tuples = ApiKey.Split(';'); + + // if only one tuple is supplied, it's just the key, no role or list of CIDRs + if (tuples.Length == 1) + { + var key = tuples.FirstOrDefault(); + + if (key?.Length < 16 || key?.Length > 255) + { + results.Add(new ValidationResult("API key must be between 16 and 255 characters")); + } + } + + foreach (var tuple in tuples) + { + if (tuple.StartsWith("role=", StringComparison.OrdinalIgnoreCase)) + { + var role = tuple.Split('=').LastOrDefault(); + + if (!Enum.TryParse(typeof(Role), role, out _)) + { + results.Add(new ValidationResult($"API key role must be one of: {string.Join(", ", Enum.GetNames(typeof(Role)))}")); + } + } + else if (tuple.StartsWith("cidr=", StringComparison.OrdinalIgnoreCase)) + { + var cidrs = tuple.Split('=').LastOrDefault(); + + foreach (var cidr in cidrs.Split(',')) + { + try + { + _ = IPAddressRange.Parse(cidr); + } + catch (Exception ex) + { + results.Add(new ValidationResult($"API key CIDR {cidr} is invalid: {ex.Message}")); + } + } + } + else if (tuple?.Length < 16 || tuple?.Length > 255) + { + results.Add(new ValidationResult("API key must be between 16 and 255 characters")); + } + } + + return results; + } + /// /// JWT options. /// -- cgit v1.2.3 From c6f912f4df7cba8abc947f4ed57a23ed0e58d995 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Fri, 12 Dec 2025 19:13:15 -0600 Subject: todos --- src/slskd/Core/Options.cs | 1 + src/slskd/Core/Security/SecurityService.cs | 5 +++++ 2 files changed, 6 insertions(+) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index fc367578..ced7c96f 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1957,6 +1957,7 @@ namespace slskd public IEnumerable Validate(ValidationContext validationContext) { + // TODO: test me! var results = new List(); if (string.IsNullOrWhiteSpace(ApiKey)) diff --git a/src/slskd/Core/Security/SecurityService.cs b/src/slskd/Core/Security/SecurityService.cs index 871e6e95..c5531a35 100644 --- a/src/slskd/Core/Security/SecurityService.cs +++ b/src/slskd/Core/Security/SecurityService.cs @@ -46,6 +46,10 @@ namespace slskd OptionsAtStartup = optionsAtStartup; OptionsMonitor = optionsMonitor; + // parse the configured string into an instance of ApiKeyOptions and assign it to + // AdministrativeApiKey, if a string is provided. + // this is kind of expensive in terms of allocations, so do it once at instantiation + // and mark the option with [RequiresRestart] var adminApiKeyString = OptionsMonitor.CurrentValue.Web.Authentication.ApiKey; if (!string.IsNullOrWhiteSpace(adminApiKeyString)) @@ -101,6 +105,7 @@ namespace slskd { var keys = OptionsMonitor.CurrentValue.Web.Authentication.ApiKeys.AsEnumerable(); + // TODO: test me! if (AdministrativeApiKey is not null) { keys = keys.Prepend(new KeyValuePair(nameof(AdministrativeApiKey), AdministrativeApiKey)); -- cgit v1.2.3 From 8fadf7bdd6b253895a273fe6ffc8bd4943f07ee9 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 13 Dec 2025 11:48:45 -0600 Subject: tweak validation --- src/slskd/Core/Options.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index ced7c96f..43363654 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1944,6 +1944,8 @@ namespace slskd /// Gets the primary API key. Defaults to 'Administrator' role and CIDR '0.0.0.0/0,::/0'. /// role and CIDR can be supplied by prefixing the key with 'role=[role];cidr=[cidrs];[key]'. /// + [Argument('k', "api-key")] + [EnvironmentVariable("API_KEY")] [Description("Administrative API key value")] [Secret] [RequiresRestart] @@ -1957,7 +1959,6 @@ namespace slskd public IEnumerable Validate(ValidationContext validationContext) { - // TODO: test me! var results = new List(); if (string.IsNullOrWhiteSpace(ApiKey)) @@ -1976,15 +1977,24 @@ namespace slskd { results.Add(new ValidationResult("API key must be between 16 and 255 characters")); } + + return results; } + /* + if multiple tuples are supplied, verify that: + + * if a tuple starts with 'role=', it's defining a role and it must match one of the Role enum values + * if a tuple starts with 'cidr=', it's defining a list of CIDRs which need to be valid + * if a tuple doesn't start with a prefix, it's the API key itself and it must be between 16 and 255 characters + */ foreach (var tuple in tuples) { if (tuple.StartsWith("role=", StringComparison.OrdinalIgnoreCase)) { var role = tuple.Split('=').LastOrDefault(); - if (!Enum.TryParse(typeof(Role), role, out _)) + if (!Enum.TryParse(typeof(Role), value: role, ignoreCase: true, out _)) { results.Add(new ValidationResult($"API key role must be one of: {string.Join(", ", Enum.GetNames(typeof(Role)))}")); } -- cgit v1.2.3 From 9296ec4295a7d6a2371e19d38d6a32ef285eb373 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 13 Dec 2025 16:00:53 -0600 Subject: administrative -> primary --- src/slskd/Core/Options.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/slskd/Core/Options.cs') diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index 43363654..20b53f6c 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -1946,7 +1946,7 @@ namespace slskd /// [Argument('k', "api-key")] [EnvironmentVariable("API_KEY")] - [Description("Administrative API key value")] + [Description("primary API key value")] [Secret] [RequiresRestart] public string ApiKey { get; init; } -- cgit v1.2.3