-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Random User.IsInRole result when UserRole changes #8011
Comments
As I’ve found out, I’ve already been investigating this a bit, and looked at the browser requests more closely, and these are my findings so far: The cookie will be kept for as long as the requests stay within the By adding a However, and now this is very interesting, the role claim is only ever included when the
This seems very odd to me. I believe what is going on here is that when the validation interval expires, a new identity is being created which loads the roles from the database and displays the updated state. This is then available in the controller and results in the set role claim. The cookie authentication handler however then just reissues the previous identity which does not have the updated roles. It would be correct for the cookie handler to reuse the existing identity (since as per the security stamp validation, the identity is still valid), but the temporarily created identity (probably for validation purposes) should not leak outside of the validation process. So that really would be a bug. And that probably also already exists in the wild already while just being less visible since the default validation interval is 30 minutes, making this appear only for one request within 30 minutes and as such very unlikely to be observed. |
Okay. The problem is that the
So in our case, where the security stamp is being validated is determined as valid (since it doesn’t change from a role change), we are getting in the
The principal appears to be replaced there, however when we take a look at what
So this updates the instance variable of So this is obviously a bug. I see a few variants on how we could fix this (depending on what we determine is the right behavior):
In any case, when we decide on a proper solution, I’ll be happy to provide the implementation, given that I’m already knee-deep in this topic. |
/cc @HaoK (since this was basically your work in aspnet/Identity#1351) (and yes, Mvc is probably the wrong repo for this :/) |
FYI, the fact the "cookies refresh" stuff doesn't work properly in 2.1 is due to a known bug: aspnet/Security#1788 |
Looks like they're going with Option 1; aspnet/Security#1795 :smile |
*sigh* Guess I am too late to the party 😢 Guess we can close this then @ans-ashkan. I have also answered your SO question with a better approach. |
Thanks everyone, It's nice to have such awesome community (which also is super fast). |
I'm glad you came to the same conclusion I did for the fix @poke :) But yeah this was a regression |
Is this a Bug or Feature request?:
Bug
Steps to reproduce (preferably a link to a GitHub repo with a repro project):
Clone and Run this project
do the following in order:
Description of the problem:
I'm using asp.net core 2.1 with some default identity settings and every time a role is changed the user should re-login to see the role changes.
If I invalidate Identity on each request with the following settings, then roles should be updated but UserIsInRole returns random results.
Version of
Microsoft.AspNetCore.Mvc
orMicrosoft.AspNetCore.App
orMicrosoft.AspNetCore.All
:Microsoft.AspNetCore.App 2.1.1
SO question of this issue
The text was updated successfully, but these errors were encountered: