From 8dda4fdf96e512d0239415dd2d7292ae848a87fd Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Sat, 7 Nov 2026 15:45:18 -0800 Subject: [PATCH] ServerPack web open: a request never prints its URL; Windows error wording WebOpenRequest is a record, so its generated ToString printed the URL, which can carry a one-time code. It now names the title only. The browser failure reads "Couldn't open your browser (Windows error N)." Co-Authored-By: Claude Opus 5.5 --- Plugins/Shared/ServerPack/ServerPackWeb.cs | 4 ++-- Plugins/Shared/ServerPack/ServerWebOpen.cs | 10 ++++++++-- .../RynthServerPack.Tests/ServerWebOpenTests.cs | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Plugins/Shared/ServerPack/ServerPackWeb.cs b/Plugins/Shared/ServerPack/ServerPackWeb.cs index cabecd7..d2ee718 100644 --- a/Plugins/Shared/ServerPack/ServerPackWeb.cs +++ b/Plugins/Shared/ServerPack/ServerPackWeb.cs @@ -70,12 +70,12 @@ public sealed partial class ServerPackPlugin { long code = ShellExecuteW(IntPtr.Zero, "open", url, null, null, 1).ToInt64(); ok = code > 32; - message = ok ? "Opened in your browser." : $"Couldn't open your browser (code {code})."; + message = ok ? "Opened in your browser." : $"Couldn't open your browser (Windows error {code})."; } catch (Exception) { ok = false; - message = "Couldn't open your browser (code 0)."; + message = "Couldn't open your browser (Windows error 0)."; } Finish(done, new WebOpenOutcome(WebOpenRoute.Browser, ok, message)); }) diff --git a/Plugins/Shared/ServerPack/ServerWebOpen.cs b/Plugins/Shared/ServerPack/ServerWebOpen.cs index 7b0392c..760c526 100644 --- a/Plugins/Shared/ServerPack/ServerWebOpen.cs +++ b/Plugins/Shared/ServerPack/ServerWebOpen.cs @@ -7,8 +7,14 @@ using System.Collections.Generic; namespace RynthCore.Plugin.ServerPack; -/// A page to open. The URL comes from constants in the plugin, never from chat. -internal sealed record WebOpenRequest(string Url, IReadOnlyList AllowedHosts, string ProfileKey, string Title); +/// +/// A page to open. The URL comes from constants in the plugin, never from chat, but it may carry a +/// one-time code, so ToString names the title only (a record's generated ToString would print the URL). +/// +internal sealed record WebOpenRequest(string Url, IReadOnlyList AllowedHosts, string ProfileKey, string Title) +{ + public override string ToString() => "WebOpenRequest(" + Title + ")"; +} internal enum WebOpenRoute { Panel, Browser, Refused } diff --git a/Tools/RynthServerPack.Tests/ServerWebOpenTests.cs b/Tools/RynthServerPack.Tests/ServerWebOpenTests.cs index 25ffd9e..a17c88f 100644 --- a/Tools/RynthServerPack.Tests/ServerWebOpenTests.cs +++ b/Tools/RynthServerPack.Tests/ServerWebOpenTests.cs @@ -10,12 +10,28 @@ internal static class ServerWebOpenTests public static void Register(Runner r) { r.Add("web open: only https on an allowed host, and the route follows the engine", Rules); + r.Add("web open: a request never prints its URL, and the browser's error says Windows", NoUrlInText); } private static readonly string[] Hosts = { "www.acdreamweave.com" }; private static readonly string[] Wild = { "*.acdreamweave.com" }; private const string Key = "dreamweave/0123456789abcdef0123456789abcdef"; + private static void NoUrlInText() + { + const string secret = "AbCdEfGhIjKlMnOpQrStUvWxYz0123456789-_AbCde"; + var r = new WebOpenRequest("https://www.acdreamweave.com/launch?code=" + secret + "&to=%2Fmarket", Hosts, Key, "DreamWeave"); + Check.Eq(r.ToString(), "WebOpenRequest(DreamWeave)", "ToString names the title only"); + Check.False(r.ToString().Contains(secret, StringComparison.Ordinal), "ToString never carries the code"); + Check.False(("" + r).Contains("acdreamweave", StringComparison.Ordinal), "nor the URL"); + Check.False((r with { Title = "x" }).ToString().Contains(secret, StringComparison.Ordinal), "a copy neither"); + + string web = System.IO.File.ReadAllText(System.IO.Path.Combine(ServerProjectsTests.PluginsDir(), "Shared", "ServerPack", "ServerPackWeb.cs")); + Check.True(web.Contains("$\"Couldn't open your browser (Windows error {code}).\"", StringComparison.Ordinal), "the browser failure names the Windows error"); + Check.True(web.Contains("\"Couldn't open your browser (Windows error 0).\"", StringComparison.Ordinal), "and its exception path"); + Check.False(web.Contains("(code ", StringComparison.Ordinal), "the old \"(code N)\" wording is gone"); + } + private static void Rules() { Check.True(ServerWebOpen.IsAllowedUrl("https://www.acdreamweave.com/x", Hosts), "https on the host");