feat: harden gateway reply remap and leaf loop transparency

This commit is contained in:
Joseph Doherty
2026-02-23 14:40:07 -05:00
parent d83b37fec1
commit 958c4aa8ed
5 changed files with 70 additions and 10 deletions

View File

@@ -4,6 +4,10 @@ public static class ReplyMapper
{
private const string GatewayReplyPrefix = "_GR_.";
public static bool HasGatewayReplyPrefix(string? subject)
=> !string.IsNullOrWhiteSpace(subject)
&& subject.StartsWith(GatewayReplyPrefix, StringComparison.Ordinal);
public static string? ToGatewayReply(string? replyTo, string localClusterId)
{
if (string.IsNullOrWhiteSpace(replyTo))
@@ -16,14 +20,20 @@ public static class ReplyMapper
{
restoredReply = string.Empty;
if (string.IsNullOrWhiteSpace(gatewayReply) || !gatewayReply.StartsWith(GatewayReplyPrefix, StringComparison.Ordinal))
if (!HasGatewayReplyPrefix(gatewayReply))
return false;
var clusterSeparator = gatewayReply.IndexOf('.', GatewayReplyPrefix.Length);
if (clusterSeparator < 0 || clusterSeparator == gatewayReply.Length - 1)
return false;
var current = gatewayReply!;
while (HasGatewayReplyPrefix(current))
{
var clusterSeparator = current.IndexOf('.', GatewayReplyPrefix.Length);
if (clusterSeparator < 0 || clusterSeparator == current.Length - 1)
return false;
restoredReply = gatewayReply[(clusterSeparator + 1)..];
current = current[(clusterSeparator + 1)..];
}
restoredReply = current;
return true;
}
}