Skip to content

Commit

Permalink
Truncate IpAddresses of IdentitySession.
Browse files Browse the repository at this point in the history
Resolve #20794
  • Loading branch information
maliming committed Sep 18, 2024
1 parent f96b918 commit 4c14a4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public class IdentitySessionConsts

public static int MaxClientIdLength { get; set; } = 64;

public static int MaxIpAddressesLength { get; set; } = 256;
public static int MaxIpAddressesLength { get; set; } = 2048;
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,22 @@ public IEnumerable<string> GetIpAddresses()
private static string JoinAsString(IEnumerable<string> list)
{
var serialized = string.Join(",", list);
return serialized.IsNullOrWhiteSpace() ? null : serialized;
if (serialized.IsNullOrWhiteSpace())
{
return null;
}

while (serialized.Length > IdentitySessionConsts.MaxIpAddressesLength)
{
var lastCommaIndex = serialized.LastIndexOf(',');
if (lastCommaIndex < 0)
{
return serialized;
}
serialized = serialized.Substring(0, lastCommaIndex);
}

return serialized;
}

private string[] GetArrayFromString(string str)
Expand Down

0 comments on commit 4c14a4a

Please sign in to comment.