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

AF Cookie should be reused within the context of same request. #1128

Merged
merged 0 commits into from
Sep 15, 2014

Conversation

harshgMSFT
Copy link
Contributor

Also adding some more functional tests for af.

@@ -56,7 +65,7 @@ public void SaveCookieToken(HttpContext httpContext, AntiForgeryToken token)
{
options.Secure = true;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

remove.

@harshgMSFT
Copy link
Contributor Author

cc @GrabYourPitchforks , @Tratcher

@@ -25,7 +25,12 @@ public AntiForgeryToken GetCookieToken(HttpContext httpContext)
var cookie = httpContext.Request.Cookies[_config.CookieName];
Copy link
Member

Choose a reason for hiding this comment

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

Will GetCookieToken be called multiple times? If so then consider checking HttpContext.Items first. If it's not there then check the cookie and store the deserialized value in Items.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is lookup on request more expensive than lookup on items ( i suppose it is but want to verify).
The save happens later when SaveCookieToken is called.

@harshgMSFT harshgMSFT force-pushed the AntiForgeryPreserveCookie branch from c732eb9 to 766a3c1 Compare September 15, 2014 20:36
@harshgMSFT
Copy link
Contributor Author

@yishaigalatzer branch updated.

@yishaigalatzer
Copy link
Contributor

:shipit: and try to get a second set of eyes on it

// Add the cookie to the request based context.
// This is useful if the cookie needs to be reloaded in the context of the same request.
var contextAccessor = httpContext.RequestServices.GetService<IContextAccessor<AntiForgeryContext>>();
if (contextAccessor.Value == null)
Copy link
Member

Choose a reason for hiding this comment

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

Assert == null, not If

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would think that the assert is also not needed, the value should be overwritten if SaveCookie is called multiple times with a different cookie value.

Copy link
Member

Choose a reason for hiding this comment

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

Calling SaveCookieToken multiple times on the same request is what caused this bug in the first place.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well, sure... I don't see the downside of adding it.

@Tratcher
Copy link
Member

:shipit:

@harshgMSFT harshgMSFT force-pushed the AntiForgeryPreserveCookie branch 2 times, most recently from 47cd611 to 9de52b3 Compare September 15, 2014 22:15
@harshgMSFT harshgMSFT merged commit 0c13563 into dev Sep 15, 2014
@harshgMSFT harshgMSFT force-pushed the AntiForgeryPreserveCookie branch from 9de52b3 to 0c13563 Compare September 15, 2014 23:31
@harshgMSFT harshgMSFT deleted the AntiForgeryPreserveCookie branch September 15, 2014 23:31
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.

3 participants