Registry Mirror
Skip to content

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

Description

@jgtestw

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.
#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

Activity

  1. added
    needs-area-label
    on Nov 11, 2025
  2. added
    area-auth
    and removed
    needs-area-label
    on Nov 11, 2025
  3. MackinnonBuck commented on Nov 12, 2025

    @MackinnonBuck
    Member

    Thanks for reaching out, @jgtestw.

    Would you mind clarifying why you're setting SlidingExpiration to true, but context.Properties.AllowRefresh to false? What's the scenario?

  4. added
    Needs: Author Feedback
    on Nov 12, 2025
  5. jgtestw commented on Nov 12, 2025

    @jgtestw
    Author

    @MackinnonBuck Because I asked ChatGPT what the purpose of AllowRefresh is, and it told me that the purpose is to override SlidingExpiration on per request basis. That means, even if SlidingExpiration is true, if AllowRefrsh is false, there should be no session extension.

    This rule is respected in the sliding expiration logic, but not in the security stamp logic, seems like an oversight.

    This is not causing me any problem, I just noticed it and it looks wrong.

  6. added
    Needs: Attention 👋
    and removed
    Needs: Author Feedback
    on Nov 12, 2025
  7. MackinnonBuck commented on Nov 17, 2025

    @MackinnonBuck
    Member

    Thanks for clarifying, @jgtestw!

    We're going to move this to the backlog to measure community impact.

  8. added and removed
    Needs: Attention 👋
    on Nov 17, 2025
  9. added this to the Backlog milestone on Nov 17, 2025
  10. added
    help wanted
    and removed on Jan 7, 2026
  11. matantsach commented on Feb 14, 2026

    @matantsach

    Hi @MackinnonBuck — I'd like to take a look at this if it's confirmed as a bug.

    From reading the issue, it seems like the security stamp validation path in SecurityStampValidator may not be checking context.Properties.AllowRefresh before refreshing the cookie, while the sliding expiration path does respect it. If that's the case, the fix would be adding the same AllowRefresh guard to the stamp validation renewal logic.

    Before I invest time in a PR — could you confirm this is indeed a bug and not by-design behavior? Happy to dig into the code and submit a fix if so.

    Thanks!

  12. added a commit that references this issue on Mar 17, 2026
    6036010
  13. matantsach commented on Mar 17, 2026

    @matantsach

    Opened a PR for this: #65803

    The root cause is in SecurityStampValidator.SecurityStampVerified() — it unconditionally sets context.ShouldRenew = true after stamp verification, without checking AllowRefresh. The handler's own CheckForRefreshAsync() does respect AllowRefresh ?? true, so the two are inconsistent.

    The fix is a one-liner that mirrors the handler's pattern: context.ShouldRenew = context.Properties.AllowRefresh ?? true. The principal replacement still happens unconditionally (claims stay fresh in-memory), only the cookie rewrite is gated.

    I've included tests for both the bug case (AllowRefresh = false → ShouldRenew == false) and default behavior preservation (AllowRefresh not set → ShouldRenew == true).

  14. added
    bug
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-authbughelp wanted

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions