dotnet/aspnetcore

Validating the security stamp is extending the session if allowRefresh is false

开放

#64,301 创建于 2025年11月11日

 (5 条评论) (1 个反应) (0 位负责人)C# (10,653 个派生)batch import
area-authhelp wanted

仓库指标

星标
 (37,933 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In the below resolved issue, you fixed the code so that it does NOT extend the session if slidingExpiration is false. https://github.com/dotnet/aspnetcore/issues/36373

Should you not also NOT extend the session if allowRefresh is false?

I don't understand the purpose of allowRefresh really.

Expected Behavior

When the security stamp check is done, the session is not extended if allowRefresh is false, or SlidingExpiraton is false.

Steps To Reproduce

builder.Services.ConfigureApplicationCookie(options =>
{
    // Cookie settings
    options.Cookie.HttpOnly = true;
    options.ExpireTimeSpan = TimeSpan.FromMinutes(10);
    options.SlidingExpiration = true;
    options.Events.OnSigningIn = (context) => {; context.Properties.IsPersistent = true; context.Properties.AllowRefresh = false; return Task.CompletedTask; };

    
});


builder.Services.Configure<SecurityStampValidatorOptions>(options =>
{
// Revalidate every 5 minutes instead of 30
options.ValidationInterval = TimeSpan.FromMinutes(1);
    options.OnRefreshingPrincipal = async (a) => { Console.WriteLine("SEC STAMP CHECK"); };
});

Observe that when the security stamp check occurs, the session is extended.

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

贡献者指南