diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-01-16 07:56:00 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-01-16 07:56:00 -0600 |
| commit | 9c1c726f2de69dd3fd38740f5bdb7f1f76e97fcf (patch) | |
| tree | 045af7374a54c5c567f4b69224eb1f13871bda94 | |
| parent | 35fb847f92350a7751cfe0c7aca2e6ea252a9573 (diff) | |
| parent | b7f7e16ab5bce20b0fad832aff2b2ce64fbbd3fe (diff) | |
| download | slskd-9c1c726f2de69dd3fd38740f5bdb7f1f76e97fcf.tar.gz | |
Merge pull request #1606 from slskd/cidr
Un-map IPv4 IPv6 addresses (remove '::ffff' prefix), disallow such addresses to be specified in CIDR configuration
| -rw-r--r-- | src/slskd/Core/Options.cs | 20 | ||||
| -rw-r--r-- | src/slskd/Core/Security/SecurityService.cs | 8 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/slskd/Core/Options.cs b/src/slskd/Core/Options.cs index a1d9953c..68fa4d92 100644 --- a/src/slskd/Core/Options.cs +++ b/src/slskd/Core/Options.cs @@ -648,6 +648,11 @@ namespace slskd { try { + if (cidr.StartsWith("::ffff", StringComparison.OrdinalIgnoreCase)) + { + throw new Exception("IPv4 mapped IPv6 addresses are not allowed"); + } + _ = IPAddressRange.Parse(cidr); } catch (Exception ex) @@ -1116,6 +1121,11 @@ namespace slskd { try { + if (cidr.StartsWith("::ffff", StringComparison.OrdinalIgnoreCase)) + { + throw new Exception("IPv4 mapped IPv6 addresses are not allowed"); + } + _ = IPAddressRange.Parse(cidr); } catch (Exception ex) @@ -2013,6 +2023,11 @@ namespace slskd { try { + if (cidr.StartsWith("::ffff", StringComparison.OrdinalIgnoreCase)) + { + throw new Exception("IPv4 mapped IPv6 addresses are not allowed"); + } + _ = IPAddressRange.Parse(cidr); } catch (Exception ex) @@ -2096,6 +2111,11 @@ namespace slskd { try { + if (cidr.StartsWith("::ffff", StringComparison.OrdinalIgnoreCase)) + { + throw new Exception("IPv4 mapped IPv6 addresses are not allowed"); + } + _ = IPAddressRange.Parse(cidr); } catch (Exception ex) diff --git a/src/slskd/Core/Security/SecurityService.cs b/src/slskd/Core/Security/SecurityService.cs index 254b3081..84071c93 100644 --- a/src/slskd/Core/Security/SecurityService.cs +++ b/src/slskd/Core/Security/SecurityService.cs @@ -27,6 +27,7 @@ using System.Net; using System.Security.Claims; using Microsoft.IdentityModel.Tokens; using NetTools; +using Serilog; using slskd.Authentication; public class SecurityService @@ -90,6 +91,7 @@ public class SecurityService } } + private ILogger Log { get; } = Serilog.Log.ForContext<SecurityService>(); private SymmetricSecurityKey JwtSigningKey { get; } private OptionsAtStartup OptionsAtStartup { get; } private IOptionsMonitor<Options> OptionsMonitor { get; } @@ -111,6 +113,12 @@ public class SecurityService throw new NotFoundException($"Unknown API key beginning with: {key.Substring(0, 4)}"); } + // looks like '::ffff:127.0.0.1'; not compatible with CIDR.Contains(), so convert it back to IPv4 + if (callerIpAddress.IsIPv4MappedToIPv6) + { + callerIpAddress = callerIpAddress.MapToIPv4(); + } + if (!record.Value.Cidr.Split(',') .Select(cidr => IPAddressRange.Parse(cidr)) .Any(range => range.Contains(callerIpAddress))) |
