RynthDreamWeave: pin the profile-key format and enforce its contract

Golden pins for dreamweave/coldeve alice keys, a Busy-Begin stale-window pin, and Key returns null when the result fails ServerWebOpen.IsValidProfileKey.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-07 15:04:27 -08:00
commit acfd04fa46
2 changed files with 17 additions and 3 deletions

View file

@ -3,6 +3,7 @@
using System;
using System.Security.Cryptography;
using System.Text;
using RynthCore.Plugin.ServerPack;
namespace RynthCore.Plugin.RynthDreamWeave;
@ -11,13 +12,14 @@ 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}$.
/// one site's cookies together. The hash keeps the account name out of the folder name. A result that fails
/// ServerWebOpen.IsValidProfileKey (a serverId outside ^[a-z0-9-]{1,32}$) is null, never a bad key.
/// </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);
string key = serverId + "/" + Convert.ToHexString(hash).ToLowerInvariant().Substring(0, 32);
return ServerWebOpen.IsValidProfileKey(key) ? key : null;
}
}

View file

@ -347,6 +347,13 @@ internal static class DreamWeaveWebTests
Check.True(t.Begin(Market, 2_999) == LaunchBegin.TooSoon, "second begin inside the throttle is refused");
Check.True(t.OnChatLine(Line, 0x05, 70_000, out _, out _, out _) == LaunchLine.NotOurs, "a refused Begin leaves the window anchored at the first");
// A Busy Begin does not extend the stale window either.
var y = new WebLauncher();
y.Begin(Market, 0);
Check.True(y.Begin(Market, 9_999) == LaunchBegin.Busy, "second begin while pending is Busy");
y.Cancel("send failed");
Check.True(y.OnChatLine(Line, 0x05, 70_000, out _, out _, out _) == LaunchLine.NotOurs, "a Busy Begin leaves the window anchored at the first");
// Window upper boundary.
Check.Eq(LaunchWire.CodeLifetimeMs, 60_000L, "code lifetime");
var u = new WebLauncher();
@ -374,6 +381,11 @@ internal static class DreamWeaveWebTests
// 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.Eq(WebProfile.Key("dreamweave", "alice"), "dreamweave/67b613ccd746148225de235baae58eab", "key format is frozen (changing it orphans saved web logins)");
Check.Eq(WebProfile.Key("coldeve", "alice"), "coldeve/1101ebeaa4456aba9ca33cd292d7b99c", "key format is frozen (changing it orphans saved web logins)");
Check.True(WebProfile.Key("DreamWeave", "alice") == null, "uppercase server id -> null");
Check.True(WebProfile.Key("dream/weave", "alice") == null, "slash in server id -> null");
Check.True(WebProfile.Key("", "alice") == null, "empty server id -> null");
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");