Browse Source

Truncate `IpAddresses` of `IdentitySession`.

Resolve #20794
pull/20819/head
maliming 2 years ago
parent
commit
4c14a4abb3
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  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.LastIndexOf(',');
if (lastCommaIndex < 0)
{
return serialized;
}
serialized = serialized.Substring(0, lastCommaIndex);
}
return serialized;
}
private string[] GetArrayFromString(string str)

Loading…
Cancel
Save