DreamWeave: website links in the bar icon's dropdown #4

Open
AwfulWaffle wants to merge 29 commits from AwfulWaffle/RynthServers:dreamweave-bar-menu into main
3 changed files with 49 additions and 0 deletions
Showing only changes of commit 2522534979 - Show all commits

RynthDreamWeave: per-account web profile key

WebProfile.Key(serverId, account) = serverId/ + 32 lowercase hex of SHA-256 over the server id and the trimmed, lower-cased account; null without an account. Keys pass ServerWebOpen.IsValidProfileKey.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Daniel Wallace 2026-11-07 15:01:35 -08:00

View file

@ -0,0 +1,23 @@
// The per-account web profile key: each account gets its own WebView2 profile folder, so website
// cookies never cross accounts. Pure, so RynthServerPack.Tests compiles it directly.
using System;
using System.Security.Cryptography;
using System.Text;
namespace RynthCore.Plugin.RynthDreamWeave;
internal static class WebProfile
{
/// <summary>
/// "serverId/" plus the first 32 lowercase hex chars of SHA-256(UTF-8(serverId + "\n" + the trimmed,
/// lower-cased account)); null when there is no account. The server id (not the world name) keeps
/// one site's cookies together. The hash keeps the account name out of the folder name. The result
/// passes ServerWebOpen.IsValidProfileKey when serverId matches ^[a-z0-9-]{1,32}$.
/// </summary>
public static string? Key(string serverId, string? account)
{
if (string.IsNullOrWhiteSpace(account)) return null;
byte[] hash = SHA256.HashData(Encoding.UTF8.GetBytes(serverId + "\n" + account.Trim().ToLowerInvariant()));
return serverId + "/" + Convert.ToHexString(hash).ToLowerInvariant().Substring(0, 32);
}
}

View file

@ -27,6 +27,7 @@ internal static class DreamWeaveWebTests
r.Add("dreamweave web: reset keeps the throttle", ResetKeepsThrottle);
r.Add("dreamweave web: a late code is eaten while it could still be valid", LateCodeIsStale);
r.Add("dreamweave web: overlapping requests never leak a code to chat", OverlappingRequests);
r.Add("dreamweave web: profile keys separate accounts", ProfileKeys);
}
private const string Code = "AbCdEfGhIjKlMnOpQrStUvWxYz0123456789-_AbCde"; // 43 chars
@ -354,6 +355,30 @@ internal static class DreamWeaveWebTests
Check.True(u.OnChatLine(Line, 0x05, 70_000, out _, out _, out _) == LaunchLine.NotOurs, "+70,000 not ours");
}
private static void ProfileKeys()
{
string? a = WebProfile.Key("dreamweave", "Alice");
string? b = WebProfile.Key("dreamweave", "Bob");
Check.True(a != null && b != null, "keys exist");
Check.True(a != b, "different accounts -> different keys");
Check.Eq(WebProfile.Key("dreamweave", " alice "), a, "trimmed and case-folded");
Check.Eq(WebProfile.Key("dreamweave", "ALICE"), a, "case-folded");
Check.Eq(WebProfile.Key("dreamweave", "Alice"), a, "stable across calls");
Check.True(WebProfile.Key("coldeve", "Alice") != a, "same account, other server -> different key");
Check.True(a!.StartsWith("dreamweave/", StringComparison.Ordinal), "prefixed by the server id");
string[] accounts = { "Alice", "Bob", "a", "x y", "caf" + (char)0xE9, "A-very-long-account-name-0123456789-0123456789-0123456789" };
foreach (string acct in accounts)
{
string? k = WebProfile.Key("dreamweave", acct);
Check.True(ServerWebOpen.IsValidProfileKey(k), "valid key for " + acct.Length + " chars");
// A 1-2 char account could appear in the server id or the hex by chance; the rest cannot.
if (acct.Length >= 3) Check.True(!k!.Contains(acct.Trim().ToLowerInvariant()), "key never contains the account text");
}
Check.True(WebProfile.Key("dreamweave", null) == null, "null account -> null");
Check.True(WebProfile.Key("dreamweave", "") == null, "empty account -> null");
Check.True(WebProfile.Key("dreamweave", " ") == null, "blank account -> null");
}
private static void OverlappingRequests()
{
// Scenario 1: request 1 times out, request 2 begins, request 1's late code arrives.

View file

@ -38,6 +38,7 @@
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthDreamWeave\DreamWeave\DreamWeaveWeb.cs" Link="DreamWeave\DreamWeaveWeb.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthDreamWeave\DreamWeave\LaunchWire.cs" Link="DreamWeave\LaunchWire.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthDreamWeave\DreamWeave\WebLauncher.cs" Link="DreamWeave\WebLauncher.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthDreamWeave\DreamWeave\WebProfile.cs" Link="DreamWeave\WebProfile.cs" />
<!-- RynthConquest's own features (pure parts) and the RynthOracle sources it links. -->
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthConquest\Conquest\ConquestData.cs" Link="Conquest\ConquestData.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthConquest\Conquest\ConquestFeature.cs" Link="Conquest\ConquestFeature.cs" />