From e428f65c4d2c902b6a65cfeb34fcb1a2b1d0aa65 Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Sat, 7 Nov 2026 14:19:55 -0800 Subject: [PATCH] Web panel: IsAllowed fails closed on invalid IDN hosts Uri.IdnHost throws UriFormatException for hosts like c; catch and reject. Test project now runs with ICU so the case is covered. Co-Authored-By: Claude Opus 5.5 --- src/RynthCore.Engine/WebPanel/WebPanelUrlPolicy.cs | 4 +++- tools/WebPanelTests/Program.cs | 1 + tools/WebPanelTests/WebPanelTests.csproj | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/RynthCore.Engine/WebPanel/WebPanelUrlPolicy.cs b/src/RynthCore.Engine/WebPanel/WebPanelUrlPolicy.cs index 1b94aab..b572b54 100644 --- a/src/RynthCore.Engine/WebPanel/WebPanelUrlPolicy.cs +++ b/src/RynthCore.Engine/WebPanel/WebPanelUrlPolicy.cs @@ -77,7 +77,9 @@ internal static class WebPanelUrlPolicy if (uri.UserInfo.Length != 0) return false; if (!uri.IsDefaultPort) return false; - string host = uri.IdnHost.ToLowerInvariant(); + string host; + try { host = uri.IdnHost.ToLowerInvariant(); } + catch (UriFormatException) { return false; } // invalid IDN characters: fail closed if (host.EndsWith('.')) host = host.Substring(0, host.Length - 1); if (host.Length == 0) return false; diff --git a/tools/WebPanelTests/Program.cs b/tools/WebPanelTests/Program.cs index 99d8e0b..581b485 100644 --- a/tools/WebPanelTests/Program.cs +++ b/tools/WebPanelTests/Program.cs @@ -71,6 +71,7 @@ internal static class Program }) Check(!WebPanelUrlPolicy.IsAllowed(u, Dw), "rejects " + u); Check(!WebPanelUrlPolicy.IsAllowed("https://www.acdreamweave.com/" + new string('a', 5000), Dw), "over MaxUrlBytes rejected"); + Check(!WebPanelUrlPolicy.IsAllowed("https://www.acdreamweave.c\u2100/", Dw), "invalid IDN char fails closed (no throw)"); } private static void Allowlist_CaseIdnTrailingDot() diff --git a/tools/WebPanelTests/WebPanelTests.csproj b/tools/WebPanelTests/WebPanelTests.csproj index 1ca3121..3a4bac0 100644 --- a/tools/WebPanelTests/WebPanelTests.csproj +++ b/tools/WebPanelTests/WebPanelTests.csproj @@ -11,7 +11,8 @@ net10.0 enable enable - true + + false WebPanelTests