Browse Source

Merge pull request #20819 from abpframework/Session-IpAddresses

Truncate `IpAddresses` of `IdentitySession`.
pull/20948/head
liangshiwei 2 years ago
committed by GitHub
parent
commit
0386df36b1
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 2
      modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentitySessionConsts.cs
  2. 17
      modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySession.cs

2
modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentitySessionConsts.cs

@ -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;
}

17
modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySession.cs

@ -80,7 +80,22 @@ public class IdentitySession : BasicAggregateRoot<Guid>, IMultiTenant
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.IndexOf(',');
if (lastCommaIndex < 0)
{
return serialized;
}
serialized = serialized.Substring(lastCommaIndex + 1);
}
return serialized;
}
private string[] GetArrayFromString(string str)

Loading…
Cancel
Save