From 8206889adac0e3d208cf29940181cae3d4fb64ff Mon Sep 17 00:00:00 2001 From: yagmurcelk <157795849+yagmurcelk@users.noreply.github.com> Date: Wed, 11 Nov 2026 11:15:17 +0000 Subject: [PATCH 1/2] Fix parallel dynamic claims refresh cookie race Overwrite dynamic claims cache on refresh instead of clear-then-refill so concurrent AuthServer refreshes cannot leave an empty cache window that rejects cookies on tiered clients. Also retry the remote cache read once after refresh when another clear still races the first read. Co-authored-by: Cursor --- ...amicClaimsPrincipalContributorCacheBase.cs | 18 ++++ ...aimsPrincipalContributorCacheBase_Tests.cs | 84 +++++++++++++++++++ .../Abp/Account/DynamicClaimsAppService.cs | 4 +- ...yDynamicClaimsPrincipalContributorCache.cs | 73 +++++++++++----- ...icClaimsPrincipalContributorCache_Tests.cs | 50 +++++++++++ 5 files changed, 209 insertions(+), 20 deletions(-) create mode 100644 framework/test/Volo.Abp.Security.Tests/Volo/Abp/Security/Claims/RemoteDynamicClaimsPrincipalContributorCacheBase_Tests.cs create mode 100644 modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityDynamicClaimsPrincipalContributorCache_Tests.cs diff --git a/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/RemoteDynamicClaimsPrincipalContributorCacheBase.cs b/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/RemoteDynamicClaimsPrincipalContributorCacheBase.cs index 23b2fbd56b..5d2f13352d 100644 --- a/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/RemoteDynamicClaimsPrincipalContributorCacheBase.cs +++ b/framework/src/Volo.Abp.Security/Volo/Abp/Security/Claims/RemoteDynamicClaimsPrincipalContributorCacheBase.cs @@ -45,6 +45,24 @@ public abstract class RemoteDynamicClaimsPrincipalContributorCacheBase(() => cache.GetAsync(userId)); + + exception.Message.ShouldContain(userId.ToString()); + exception.Message.ShouldContain("from cache after refreshing"); + cache.RefreshCallCount.ShouldBe(2); + } + + private class TestRemoteDynamicClaimsPrincipalContributorCache + : RemoteDynamicClaimsPrincipalContributorCacheBase + { + private readonly int _missCountAfterRefresh; + private readonly AbpDynamicClaimCacheItem _cacheItem; + private int _getAfterRefreshCount; + + public int RefreshCallCount { get; private set; } + + public TestRemoteDynamicClaimsPrincipalContributorCache( + IOptions options, + int missCountAfterRefresh, + AbpDynamicClaimCacheItem cacheItem) + : base(options) + { + _missCountAfterRefresh = missCountAfterRefresh; + _cacheItem = cacheItem; + } + + protected override Task GetCacheAsync(Guid userId, Guid? tenantId = null) + { + if (RefreshCallCount == 0) + { + return Task.FromResult(null); + } + + _getAfterRefreshCount++; + if (_getAfterRefreshCount <= _missCountAfterRefresh) + { + return Task.FromResult(null); + } + + return Task.FromResult(_cacheItem); + } + + protected override Task RefreshAsync(Guid userId, Guid? tenantId = null) + { + RefreshCallCount++; + return Task.CompletedTask; + } + } +} diff --git a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/DynamicClaimsAppService.cs b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/DynamicClaimsAppService.cs index e26dbfc979..d928b7aaa1 100644 --- a/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/DynamicClaimsAppService.cs +++ b/modules/account/src/Volo.Abp.Account.Application/Volo/Abp/Account/DynamicClaimsAppService.cs @@ -25,7 +25,9 @@ public class DynamicClaimsAppService : IdentityAppServiceBase, IDynamicClaimsApp public virtual async Task RefreshAsync() { - await IdentityDynamicClaimsPrincipalContributorCache.ClearAsync(CurrentUser.GetId(), CurrentUser.TenantId); + // Overwrite the cache in place. Do not Clear then refill: parallel refresh requests + // would leave a gap where remote clients read null and reject the auth cookie. + await IdentityDynamicClaimsPrincipalContributorCache.RefreshAsync(CurrentUser.GetId(), CurrentUser.TenantId); await AbpClaimsPrincipalFactory.CreateDynamicAsync(PrincipalAccessor.Principal); } } diff --git a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDynamicClaimsPrincipalContributorCache.cs b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDynamicClaimsPrincipalContributorCache.cs index c0b5023386..44ba5b5fc5 100644 --- a/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDynamicClaimsPrincipalContributorCache.cs +++ b/modules/identity/src/Volo.Abp.Identity.Domain/Volo/Abp/Identity/IdentityDynamicClaimsPrincipalContributorCache.cs @@ -63,25 +63,7 @@ public class IdentityDynamicClaimsPrincipalContributorCache : ITransientDependen return await DynamicClaimCache.GetOrAddAsync(AbpDynamicClaimCacheItem.CalculateCacheKey(userId, tenantId), async () => { Logger.LogDebug($"Filling dynamic claims cache for user: {userId}"); - - var user = await UserManager.GetByIdAsync(userId); - var principal = await UserClaimsPrincipalFactory.CreateAsync(user); - - var dynamicClaims = new AbpDynamicClaimCacheItem(); - foreach (var claimType in AbpClaimsPrincipalFactoryOptions.Value.DynamicClaims) - { - var claims = principal.Claims.Where(x => x.Type == claimType).ToList(); - if (claims.Any()) - { - dynamicClaims.Claims.AddRange(claims.Select(claim => new AbpDynamicClaim(claimType, claim.Value))); - } - else - { - dynamicClaims.Claims.Add(new AbpDynamicClaim(claimType, null)); - } - } - - return dynamicClaims; + return await CreateCacheItemAsync(userId); }, () => new DistributedCacheEntryOptions { AbsoluteExpirationRelativeToNow = CacheOptions.Value.CacheAbsoluteExpiration @@ -89,9 +71,62 @@ public class IdentityDynamicClaimsPrincipalContributorCache : ITransientDependen } } + /// + /// Recomputes and overwrites the cached dynamic claims for the user without removing the + /// existing item first. Concurrent refresh requests must not observe an empty cache window + /// (Clear + refill races reject cookies on tiered / microservice clients). + /// + public virtual async Task RefreshAsync(Guid userId, Guid? tenantId = null) + { + Logger.LogDebug($"Refresh dynamic claims cache for user: {userId}"); + + using (CurrentTenant.Change(tenantId)) + { + AbpDynamicClaimCacheItem cacheItem; + if (AbpClaimsPrincipalFactoryOptions.Value.DynamicClaims.IsNullOrEmpty()) + { + cacheItem = new AbpDynamicClaimCacheItem(); + } + else + { + cacheItem = await CreateCacheItemAsync(userId); + } + + await DynamicClaimCache.SetAsync( + AbpDynamicClaimCacheItem.CalculateCacheKey(userId, tenantId), + cacheItem, + new DistributedCacheEntryOptions + { + AbsoluteExpirationRelativeToNow = CacheOptions.Value.CacheAbsoluteExpiration + }); + } + } + public virtual async Task ClearAsync(Guid userId, Guid? tenantId = null) { Logger.LogDebug($"Remove dynamic claims cache for user: {userId}"); await DynamicClaimCache.RemoveAsync(AbpDynamicClaimCacheItem.CalculateCacheKey(userId, tenantId)); } + + protected virtual async Task CreateCacheItemAsync(Guid userId) + { + var user = await UserManager.GetByIdAsync(userId); + var principal = await UserClaimsPrincipalFactory.CreateAsync(user); + + var dynamicClaims = new AbpDynamicClaimCacheItem(); + foreach (var claimType in AbpClaimsPrincipalFactoryOptions.Value.DynamicClaims) + { + var claims = principal.Claims.Where(x => x.Type == claimType).ToList(); + if (claims.Any()) + { + dynamicClaims.Claims.AddRange(claims.Select(claim => new AbpDynamicClaim(claimType, claim.Value))); + } + else + { + dynamicClaims.Claims.Add(new AbpDynamicClaim(claimType, null)); + } + } + + return dynamicClaims; + } } diff --git a/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityDynamicClaimsPrincipalContributorCache_Tests.cs b/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityDynamicClaimsPrincipalContributorCache_Tests.cs new file mode 100644 index 0000000000..1d5e0c72ee --- /dev/null +++ b/modules/identity/test/Volo.Abp.Identity.Domain.Tests/Volo/Abp/Identity/IdentityDynamicClaimsPrincipalContributorCache_Tests.cs @@ -0,0 +1,50 @@ +using System.Threading.Tasks; +using Shouldly; +using Volo.Abp.Caching; +using Volo.Abp.Security.Claims; +using Xunit; + +namespace Volo.Abp.Identity; + +public class IdentityDynamicClaimsPrincipalContributorCache_Tests : AbpIdentityDomainTestBase +{ + private readonly IdentityDynamicClaimsPrincipalContributorCache _cache; + private readonly IDistributedCache _distributedCache; + private readonly IdentityTestData _testData; + + public IdentityDynamicClaimsPrincipalContributorCache_Tests() + { + _cache = GetRequiredService(); + _distributedCache = GetRequiredService>(); + _testData = GetRequiredService(); + } + + [Fact] + public async Task RefreshAsync_Should_Overwrite_Cache_Without_Clearing_First() + { + var cacheKey = AbpDynamicClaimCacheItem.CalculateCacheKey(_testData.UserJohnId, null); + + await _distributedCache.SetAsync(cacheKey, new AbpDynamicClaimCacheItem()); + + await _cache.RefreshAsync(_testData.UserJohnId); + + var item = await _distributedCache.GetAsync(cacheKey); + item.ShouldNotBeNull(); + item.Claims.ShouldNotBeEmpty(); + } + + [Fact] + public async Task RefreshAsync_Should_Keep_Cache_Populated_Across_Parallel_Calls() + { + var cacheKey = AbpDynamicClaimCacheItem.CalculateCacheKey(_testData.UserJohnId, null); + + await Task.WhenAll( + _cache.RefreshAsync(_testData.UserJohnId), + _cache.RefreshAsync(_testData.UserJohnId), + _cache.RefreshAsync(_testData.UserJohnId)); + + var item = await _distributedCache.GetAsync(cacheKey); + item.ShouldNotBeNull(); + item.Claims.ShouldNotBeEmpty(); + } +} From 488a017371a4aef459ff51914fd2c15acd152f72 Mon Sep 17 00:00:00 2001 From: yagmurcelk <157795849+yagmurcelk@users.noreply.github.com> Date: Wed, 11 Nov 2026 12:34:07 +0000 Subject: [PATCH 2/2] Update LeptonX Blazor footer docs links Replace the Blazor LeptonX footer customization example that used placeholder href="#" About/Privacy/Contact links with Privacy and Cookie Policy URLs, and note that footer links should only target real pages. Co-authored-by: Cursor --- docs/en/ui-themes/lepton-x/blazor.md | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/docs/en/ui-themes/lepton-x/blazor.md b/docs/en/ui-themes/lepton-x/blazor.md index 07d07eea00..9f5ee973ca 100644 --- a/docs/en/ui-themes/lepton-x/blazor.md +++ b/docs/en/ui-themes/lepton-x/blazor.md @@ -383,20 +383,18 @@ You can add a new `LeptonXFooter.razor` file and override the `Footer` component
``` +Only include footer links that point at real pages in your solution (for example `/PrivacyPolicy` and `/CookiePolicy` when those pages exist). Do not use placeholder `href="#"` links. + If you are using **Top Menu Layout**, then you can change the namespace as follows: ```diff