fix(battle-node): header-based WS detection in auth; split unknown-bid vs mismatch logs
Previous fix used Context.WebSockets.IsWebSocketRequest, but that requires UseWebSockets() to have already run — and UseBattleNode (which calls UseWebSockets) is registered AFTER UseAuthentication in Program.cs, so the WS feature isn't installed when auth runs. Switch to reading the raw Upgrade header, which works regardless of middleware order. Also split the WS handler's "Unknown battle/viewer pair" warning into two distinct cases so we can tell unknown-BattleId from viewer-id-mismatch (which lets us see whether the bridge stored the right viewer or the client is encrypting a different id). Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -54,9 +54,20 @@ public sealed class BattleNodeWebSocketHandler
|
||||
}
|
||||
|
||||
var pending = _store.TryGetPending(battleId);
|
||||
if (pending is null || pending.ViewerId != viewerId)
|
||||
if (pending is null)
|
||||
{
|
||||
_log.LogWarning("Unknown battle/viewer pair: {Bid}/{Vid}", battleId, viewerId);
|
||||
_log.LogWarning(
|
||||
"WS upgrade for unknown BattleId={Bid} (decrypted viewerId={Vid}). " +
|
||||
"Bridge may not have minted this battle, or it was already consumed/expired.",
|
||||
battleId, viewerId);
|
||||
ctx.Response.StatusCode = StatusCodes.Status400BadRequest;
|
||||
return;
|
||||
}
|
||||
if (pending.ViewerId != viewerId)
|
||||
{
|
||||
_log.LogWarning(
|
||||
"WS upgrade viewer-id mismatch on BattleId={Bid}: bridge expected={Expected}, decrypted={Got}.",
|
||||
battleId, pending.ViewerId, viewerId);
|
||||
ctx.Response.StatusCode = StatusCodes.Status400BadRequest;
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user