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

Replace the ConfigureCookieOptions action property with the CookieBuilder #148

Merged
merged 1 commit into from
Jun 30, 2017

Conversation

natemcmaster
Copy link
Contributor

Addresses aspnet/HttpAbstractions#853.

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

cc @JunTaoLuo @rynowak @javiercn

/// </summary>
public Action<HttpContext, CookieOptions> ConfigureCookieOptions { get; set; }
Copy link
Member

Choose a reason for hiding this comment

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

Does cookie builder have something similar to this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, but we made CookieBuilder.Build(HttpContext context) virtual and AntiforgeryOptions.Cookie settable for edge cases where users need to do something with HttpContext that we don't expect.

Copy link
Member

Choose a reason for hiding this comment

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

We added this for a reason, so we'll have to figure out an alternative.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What was the reason? When we were designing CookieBuilder, we figured anything other than the already-available top-level properties is an uncommon usage of this API.

Copy link
Member

Choose a reason for hiding this comment

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

I know we did this to enable per-request configuration of things like the path, but I can't find an actual customer request for this, so I think we can just forget it until someone asks. Like you said, build is virtual, so we could use our subclass to resurrect this if necessary

public override string Name
{
get => base.Name;
set => base.Name = value ?? throw new ArgumentNullException(nameof(value));
Copy link
Member

Choose a reason for hiding this comment

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

null or empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1.x behavior only checks for null and only throws ArgumentNullException.

if (_options.CookiePath != null)
var options = _options.Cookie.Build(httpContext);

options.Secure = options.Secure || _options.RequireSsl;
Copy link
Member

Choose a reason for hiding this comment

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

Why not depend on CookieSecurePolicy?

Copy link
Member

Choose a reason for hiding this comment

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

This has historically been here along with RequireSsl. I'm not really sure if the reasons are important or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I looked through the code, and didn't find any significant reason for these to be separate options. I've pushed an update that obsoletes RequireSsl and forwards it to Cookie.SecurePolicy.

/// <para>
/// <see cref="CookieBuilder.SameSite"/> defaults to <see cref="SameSiteMode.Strict"/>.
/// <see cref="CookieBuilder.HttpOnly"/> defaults to <c>true</c>.
/// <see cref="CookieBuilder.SecurePolicy"/> will be forced to <seealso cref="CookieSecurePolicy.Always"/> when <see cref="RequireSsl"/> is <c>true</c>.
Copy link
Member

Choose a reason for hiding this comment

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

Map RequireSsl to Cookie.SecurePolicy?

@rynowak
Copy link
Member

rynowak commented Jun 30, 2017

:shipit: from me

@rynowak
Copy link
Member

rynowak commented Jun 30, 2017

RequireSsl does more than just configure the cookie policy

if (_options.RequireSsl && !context.Request.IsHttps)

@@ -265,12 +265,11 @@ private void SaveCookieTokenAndHeader(HttpContext httpContext, string cookieToke

private void CheckSSLConfig(HttpContext context)
{
if (_options.RequireSsl && !context.Request.IsHttps)
if (_options.Cookie.SecurePolicy == CookieSecurePolicy.Always && !context.Request.IsHttps)
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.

Ok cool 👍

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.

4 participants