ServerPack web open: fall back only before the panel navigates
PanelResult + pure FallbackToBrowser; guard TryOpenPanel throws; guard done callbacks; hand ShellExecuteW the validated absolute URI. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
dd80216933
commit
c085c16e15
3 changed files with 51 additions and 13 deletions
|
|
@ -12,6 +12,9 @@ internal sealed record WebOpenRequest(string Url, IReadOnlyList<string> AllowedH
|
|||
|
||||
internal enum WebOpenRoute { Panel, Browser, Refused }
|
||||
|
||||
/// <summary>What the engine's panel did. Only a refusal before navigating may fall back to the browser.</summary>
|
||||
internal enum PanelResult { Opened, RefusedBeforeNavigate, UrlNotAllowed, FailedAfterNavigate }
|
||||
|
||||
/// <summary>What happened. The message never contains the URL.</summary>
|
||||
internal sealed record WebOpenOutcome(WebOpenRoute Route, bool Ok, string Message);
|
||||
|
||||
|
|
@ -22,13 +25,25 @@ internal static class ServerWebOpen
|
|||
/// (OrdinalIgnoreCase). An entry "*.x" matches subdomains of x only, never x itself.
|
||||
/// </summary>
|
||||
public static bool IsAllowedUrl(string? url, IReadOnlyList<string> allowedHosts)
|
||||
=> TryGetAllowedUri(url, allowedHosts, out _);
|
||||
|
||||
/// <summary>The same check, giving the validated absolute URI (what the browser should be handed).</summary>
|
||||
public static bool TryGetAllowedUri(string? url, IReadOnlyList<string> allowedHosts, out string absoluteUri)
|
||||
{
|
||||
absoluteUri = string.Empty;
|
||||
if (string.IsNullOrEmpty(url) || allowedHosts == null) return false;
|
||||
if (!Uri.TryCreate(url, UriKind.Absolute, out Uri? uri)) return false;
|
||||
if (!string.Equals(uri.Scheme, "https", StringComparison.Ordinal)) return false;
|
||||
if (uri.UserInfo.Length != 0 || !uri.IsDefaultPort) return false;
|
||||
string host = uri.Host;
|
||||
if (host.Length == 0) return false;
|
||||
if (!HostAllowed(host, allowedHosts)) return false;
|
||||
absoluteUri = uri.AbsoluteUri;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool HostAllowed(string host, IReadOnlyList<string> allowedHosts)
|
||||
{
|
||||
|
||||
foreach (string entry in allowedHosts)
|
||||
{
|
||||
|
|
@ -49,6 +64,10 @@ internal static class ServerWebOpen
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Fall back to the browser only when the panel refused before navigating. After a
|
||||
/// navigate the one-time code is spent (a dead link), and UrlNotAllowed must not bypass the engine's list.</summary>
|
||||
public static bool FallbackToBrowser(PanelResult r) => r == PanelResult.RefusedBeforeNavigate;
|
||||
|
||||
/// <summary>^[a-z0-9-]{1,32}/[0-9a-f]{32}$ - the engine's panel profile key (server/token).</summary>
|
||||
public static bool IsValidProfileKey(string? key)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue