From 4c14a4abb364edc555d46cacd0c6f6d8ed45e3a1 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 18 Sep 2024 15:30:40 +0800 Subject: [PATCH 1/2] Truncate `IpAddresses` of `IdentitySession`. Resolve #20794 --- .../Volo/Abp/Identity/IdentitySessionConsts.cs | 2 +- .../Volo/Abp/Identity/IdentitySession.cs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentitySessionConsts.cs b/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentitySessionConsts.cs index 96cb8df5c99..ca047730eeb 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain.Shared/Volo/Abp/Identity/IdentitySessionConsts.cs +++ b/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; } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySession.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySession.cs index c25a6b2e823..bf0048efe2d 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySession.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySession.cs @@ -80,7 +80,22 @@ public IEnumerable GetIpAddresses() private static string JoinAsString(IEnumerable 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) From 05fd7beacda002ca42458e43dceeaf4cf657b9f6 Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 18 Sep 2024 15:36:00 +0800 Subject: [PATCH 2/2] Truncate the ip string from the beginning. --- .../Volo/Abp/Identity/IdentitySession.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySession.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySession.cs index bf0048efe2d..60ece055028 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySession.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentitySession.cs @@ -87,12 +87,12 @@ private static string JoinAsString(IEnumerable list) while (serialized.Length > IdentitySessionConsts.MaxIpAddressesLength) { - var lastCommaIndex = serialized.LastIndexOf(','); + var lastCommaIndex = serialized.IndexOf(','); if (lastCommaIndex < 0) { return serialized; } - serialized = serialized.Substring(0, lastCommaIndex); + serialized = serialized.Substring(lastCommaIndex + 1); } return serialized;