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

Add CookieBuilder to CookieAuthenticationOptions and obsolete the duplicated properties #1285

Merged
merged 1 commit into from
Jul 5, 2017

Conversation

natemcmaster
Copy link
Contributor

Addresses aspnet/HttpAbstractions#853.

Uses the new CookieBuilder API added here: aspnet/HttpAbstractions#882

@natemcmaster natemcmaster requested review from Tratcher and HaoK June 30, 2017 00:26
@dnfclas
Copy link

dnfclas commented Jun 30, 2017

@natemcmaster,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot


if (Options.CookieSecure == CookieSecurePolicy.SameAsRequest)
if (Options.Cookie.Path == null && OriginalPathBase.HasValue)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Is this doing the same thing? I'd still expect, if a cookie does have a path but I say SameAsRequest it'd match the Secure flag to the request protocol.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The diff github is showing is a little misleading. The behavior your asking about moved into the CookieBuilder:

See https://github.com/aspnet/HttpAbstractions/blob/199b0fa212aa03a011f3c18575f0ab5102527c1a/src/Microsoft.AspNetCore.Http.Abstractions/CookieBuilder.cs#L97

@Tratcher
Copy link
Member

@blowdart for a usability check

Path = Options.CookiePath ?? (OriginalPathBase.HasValue ? OriginalPathBase.ToString() : "/"),
};
var cookieOptions = Options.Cookie.Build(Context);
// ignore the 'Expires' value as this will be computed elsewhere
Copy link
Member

Choose a reason for hiding this comment

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

Didn't we add Expiration support to Build for Security, or is it being used elsewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The behavior here is funky, and FWIW one of the reasons I was suggesting we leave Expiration off CookeBuilder. This handler takes into consideration CookieSignInContext.Properties.ExpiresUtc and CookieSignInContext.Properties.IsPersistent to calculate CookieOptions.Expires. So, the value of .Expires set by the builder needs to be unset to avoid changing behavior.

https://github.com/aspnet/Security/blob/namc/cookie-options/test/Microsoft.AspNetCore.Authentication.Test/CookieTests.cs#L141

It would be good to find ways to clean this up without breaking existing behavior.

Copy link
Member

Choose a reason for hiding this comment

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

This is fine, I just wanted to make sure we are using the expires overload somewhere, and it looks like we are with the nonce/correlation cookies so its cool. Otherwise I'd have suggested removing the unused overload.

@natemcmaster natemcmaster force-pushed the namc/cookie-options branch from 4b0ee5d to c36c94d Compare June 30, 2017 19:27
@natemcmaster natemcmaster changed the base branch from dev to namc/replace-cookie-builder June 30, 2017 19:27
@natemcmaster
Copy link
Contributor Author

Updated. Rebased on #1284 so I could re-use RequestPathBaseCookieBuilder

@natemcmaster
Copy link
Contributor Author

🔔 updated to remove CookieAuthenticationOptions.CookieSameSite completely, which was never shipped as an RTM api

@natemcmaster natemcmaster force-pushed the namc/replace-cookie-builder branch from a565a24 to 968237d Compare July 5, 2017 16:58
@natemcmaster natemcmaster force-pushed the namc/cookie-options branch from 375f3c8 to a7bf561 Compare July 5, 2017 17:05
@natemcmaster natemcmaster changed the base branch from namc/replace-cookie-builder to dev July 5, 2017 17:08
@natemcmaster natemcmaster merged commit a7bf561 into dev Jul 5, 2017
@natemcmaster natemcmaster deleted the namc/cookie-options branch July 5, 2017 17:16
@@ -283,14 +270,14 @@ private CookieOptions BuildCookieOptions()

if (!signInContext.Properties.ExpiresUtc.HasValue)
{
signInContext.Properties.ExpiresUtc = issuedUtc.Add(Options.ExpireTimeSpan);
signInContext.Properties.ExpiresUtc = issuedUtc.Add(Options.Cookie.Expiration ?? default(TimeSpan));
Copy link
Member

Choose a reason for hiding this comment

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

This fallback to default(TimeSpan) doesn't make sense, you end up issuing an already expired cookie.

natemcmaster added a commit that referenced this pull request Jul 5, 2017
- Revert the obsoleting of CookieAuthenticationOptions.ExpireTimeSpan in #1285
- Add test to ensure Cookie.Expiration is ignored
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.

5 participants