Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Fix regression in Cookies #1795

Closed
wants to merge 9 commits into from
Closed

Fix regression in Cookies #1795

wants to merge 9 commits into from

Conversation

HaoK
Copy link
Member

@HaoK HaoK commented Jun 28, 2018

Fix for #1788

CookieCanBeUpdatedByValidatorDuringRefresh is the new regression test that fails for the identity scenario.

@Tratcher @ajcvickers @blowdart

OnValidatePrincipal = ctx =>
{
ctx.ShouldRenew = true;
ctx.ReplacePrincipal(new ClaimsPrincipal(new ClaimsIdentity(new GenericIdentity("Alice2", "Cookies2"))));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it not possible to update the AuthProperties at the same time?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hrm, we might have a similar bug with properties I guess due to the cloning change. Renew probably is stomping on any changes that were applied in the context

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no issue with properties because the context ends up taking the ticket properties

https://github.com/aspnet/Security/blob/master/src/Microsoft.AspNetCore.Authentication.Cookies/Events/CookieValidatePrincipalContext.cs#L23

so updates to the ticket's properties show up automatically when they get copied:

https://github.com/aspnet/Security/blob/master/src/Microsoft.AspNetCore.Authentication.Cookies/CookieAuthenticationHandler.cs#L113

since ticket.Properties == context.Properties

I'll update the test to set a property, but I don't think we need to change the fix

@natemcmaster natemcmaster changed the base branch from dev to master July 2, 2018 17:59
@blowdart
Copy link
Member

blowdart commented Jul 2, 2018

Do it.

@poke
Copy link
Contributor

poke commented Jul 4, 2018

I’ve touched on this in aspnet/Mvc#8011, and just want to check:

Do we really want to make a security stamp validation with a successful result refresh the identity, making it update all claims? Currently, we didn’t have this behavior before and an identity would always be the same until we sign in again. But with this, we are essentially updating the claims identity on every security stamp validation interval, which might be a nice but similarly also confusing side-effect.

@HaoK
Copy link
Member Author

HaoK commented Jul 5, 2018

@poke this is how this security stamp feature was originally designed to work, identity would take care of ensuring a fresh set of user claims are regenerated every so often (validationInterval), which should be determined based on a performance/staleness tradeoff since as you pointed out, its not cheap to hit the database/generate user claims.

@Tratcher
Copy link
Member

Tratcher commented Jul 5, 2018

More specifically, it worked that way in 2.0 but regressed in 2.1.

@poke
Copy link
Contributor

poke commented Jul 5, 2018

Okay, as long as that’s the desired effect, I’m happy with it ☺️

@HaoK
Copy link
Member Author

HaoK commented Jul 5, 2018

@ajcvickers I think the fix in this PR is good for patch approval now

@HaoK
Copy link
Member Author

HaoK commented Jul 11, 2018

@natemcmaster this was approved for patch, should I merge this to release/2.1 and then port it back to master?

@natemcmaster
Copy link
Contributor

Yes. Change this PR to target release/2.1 instead of master. Then, merge release/2.1 into release/2.2 (the bot hasn't automated this one yet). After that, the bot will open a PR to merge your release/2.2 change into master.

@HaoK HaoK changed the base branch from master to release/2.1 July 11, 2018 20:02
@HaoK
Copy link
Member Author

HaoK commented Jul 11, 2018

Replaced by #1811 since the rebase didn't go well

@HaoK HaoK closed this Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants