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

Add SameSitePolicy to CookiePolicyMiddleware #1222

Merged
merged 1 commit into from
May 23, 2017
Merged

Conversation

JunTaoLuo
Copy link
Contributor

@JunTaoLuo JunTaoLuo commented May 19, 2017

Addresses #908 Reacting to aspnet/HttpAbstractions#843. Still need to update defaults.

@JunTaoLuo JunTaoLuo requested a review from Tratcher May 19, 2017 03:20
@dnfclas
Copy link

dnfclas commented May 19, 2017

@JunTaoLuo,
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

options.SameSite = SameSiteEnforcementMode.Strict;
break;
default:
throw new InvalidOperationException();
Copy link

Choose a reason for hiding this comment

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

Would it be easier for a developer to diagnose this case if an error message were provided here?

Copy link
Member

Choose a reason for hiding this comment

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

Poicy.SameSite.ToString(). This is more of an assert for if we add more enum values in the future.

@@ -23,6 +22,7 @@ public CookieAuthenticationOptions()
ReturnUrlParameter = CookieAuthenticationDefaults.ReturnUrlParameter;
ExpireTimeSpan = TimeSpan.FromDays(14);
SlidingExpiration = true;
CookieSameSite = SameSiteEnforcementMode.None;
Copy link
Member

Choose a reason for hiding this comment

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

Strict? @blowdart

Copy link
Member

Choose a reason for hiding this comment

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

Probably. Strict would break, for example, links to a protected resource from another site. But given we try to be secure by default ... yea, strict.

options.SameSite = SameSiteEnforcementMode.Strict;
break;
default:
throw new InvalidOperationException();
Copy link
Member

Choose a reason for hiding this comment

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

Poicy.SameSite.ToString(). This is more of an assert for if we add more enum values in the future.

public enum SameSitePolicy
{
None = 0,
LaxOrStrict,
Copy link
Member

Choose a reason for hiding this comment

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

Names need work. The policy specifies the minimum required level. Maybe you don't need a new enum, you can use the existing one and just name the option SameSiteMinimum.

@JunTaoLuo
Copy link
Contributor Author

🆙 📅

@JunTaoLuo
Copy link
Contributor Author

ping

@JunTaoLuo
Copy link
Contributor Author

This is currently blocking the build since MVC functional tests depends on these changes to pass. Otherwise we need to revert the HttpAbstractions commit.

@@ -899,6 +899,7 @@ private void WriteNonceCookie(string nonce)
new CookieOptions
{
HttpOnly = true,
SameSite = Http.SameSiteMode.Lax,
Copy link
Member

Choose a reason for hiding this comment

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

using?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to differentiate between the one in M.A.Http and M.Net.Http.Headers. Both usings are already present and required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Brings up a good point, Should I be using the one from M.A.Http or M.Net.Http.Headers when I have the choice? Is there a preference for any particular one?

Copy link
Member

Choose a reason for hiding this comment

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

Stick with the aspnet one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup that's the one I try to use as much as possible.


namespace Microsoft.AspNetCore.CookiePolicy
{
public enum MinimumSameSiteStrictnessPolicy
Copy link
Member

Choose a reason for hiding this comment

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

MinimumSameSitePolicy?
Since the values match the underlying enum, do we actually need this one?

Copy link
Contributor Author

@JunTaoLuo JunTaoLuo May 23, 2017

Choose a reason for hiding this comment

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

Ah yes, it used to be different since there were None, LaxOrStrict, and AlwaysStrict. But now it makes sense to just name the variable differently.

@JunTaoLuo JunTaoLuo merged commit 769da5f into dev May 23, 2017
@JunTaoLuo JunTaoLuo deleted the johluo/samesite branch May 23, 2017 16:57
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.

None yet

5 participants