Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SameSite cookie (Strict, Lax, None) #1328

Open
kiennguyen opened this issue Jan 30, 2020 · 23 comments · May be fixed by #1369
Open

Support SameSite cookie (Strict, Lax, None) #1328

kiennguyen opened this issue Jan 30, 2020 · 23 comments · May be fixed by #1369
Labels

Comments

@kiennguyen
Copy link

kiennguyen commented Jan 30, 2020

Are you looking for help?

From Google Chrome 80, they are planning to released from february, 2020, they will force SameSite=None for all Cookies if we want to use for third-party context. If no SameSite is set, then Chrome will understand as SameSite=Lax. It seems to be reversed the result as before (SameSite=None by default). Please see: https://www.chromium.org/updates/same-site
Therefore, we need to update our cookies with declarative setting SameSite from Playframework Controller.

Play Version (1.5.x / etc)

Playframework 1.5.x

Expected Behavior

  1. Support SameSite enum inside the Http.Cookie
  2. SameSite enum supports three values: Strict, Lax and None
@jvosloo
Copy link

jvosloo commented Jan 31, 2020

How exactly would you do that in a controller?

@miller11
Copy link

@jvosloo I think what @kiennguyen is getting at is just extending the cookie interface to allow us to set the SameSite attribute just like we can currently set other cookie attributes like expiration or httpOnly.

@jvosloo
Copy link

jvosloo commented Jan 31, 2020

Ah ok, I see in Play2 the default seems to be "lax": https://www.playframework.com/documentation/2.8.x/SettingsSession

Would that be a sensible default for Play1 as well then?

@miller11
Copy link

That is an interesting choice. I would think that not setting it all would be best default since that is the current behavior and it mimics things like expiration and httpOnly. Another thing to consider is not all browsers support the SameSite attribute so setting it lax by default may cause issues with some browsers.

@jvosloo
Copy link

jvosloo commented Jan 31, 2020

I hear you. Check out this discussion: playframework/playframework#7316

@kiennguyen
Copy link
Author

Thanks @miller11 . Yes, we just want to have possibility to set SameSite property like httpOnly or maxAge in Http.Cookie class. No need to have default value.

@kiennguyen
Copy link
Author

@jvosloo Is that clear? Do you know the plan to have this feature in the play 1.5.x?

@jvosloo
Copy link

jvosloo commented Feb 13, 2020

@kiennguyen makes sense to me yes. I'm not not one of the committers, so can't answer on the plan. Perhaps @miller11 has an idea

@miller11
Copy link

miller11 commented Feb 13, 2020

Also not a committer, however I don't think this is a simple path forward. Play uses the Cookie interface from Netty to set cookies as seen in the PlayHandler.java. As you can see even in the newest 4.1 release of Netty they don't yet support the SameSite attribute (Play 1.5.3 is currently on Netty 3.10.6.Final .

There is an issue in the Netty repo and even a PR for SameSite support, but seems like there is some discussion when this would get merged.

One annoying issue to note about the SameSite attribute is that it doesn't seem to be respected uniformly across browsers yet.

@tomparle
Copy link
Contributor

tomparle commented Feb 13, 2020

Thanks everyone for your involvement and suggestions so far !
It seems that Netty will only include this in version 5.x and up for compatibility reasons.
Regarding migration from Netty 3, I did some progress could not complete it : #1284 <= some help will be needed here because Play core's code was starting to be too tricky for me to migrate, unfortunately.

@xabolcs
Copy link
Contributor

xabolcs commented Mar 11, 2020

Netty 4 support is almost ready to ship.

netty/netty#10050

@dumedeiros
Copy link

Does anyone already know how to add SameSite?

@Alexandermjos
Copy link

Alexandermjos commented Jan 4, 2022

Hi all.
Is anyone working on samesite for play 1.x?

I have a working version / custom build based on Play 1.5.2 which has support for samesite

@miller11 Play classes is extending netty classes, so netty doesnt need to support samesite?
edit: Sorry, I mixed my own files 🤣

@tazmaniax
Copy link
Collaborator

@Alexandermjos very interested to see what you have, can you create a pull request?

Alexandermjos added a commit to Alexandermjos/play1 that referenced this issue Jan 5, 2022
@Alexandermjos Alexandermjos linked a pull request Jan 5, 2022 that will close this issue
5 tasks
@Alexandermjos
Copy link

@tazmaniax I have created a pull request. I ended up starting from scratch and not using the implementation I had based on Play 1.5.2, more info regarding that in the PR. Looking forward for feedback 😃 I have not added any as reviewers. Should I add someone, or do people of interests add themselves? This is my first PR to an open source project, so not sure if I did everything correct. 🤞

@tazmaniax
Copy link
Collaborator

tazmaniax commented Jan 5, 2022

@Alexandermjos looks good. I can see there was some discussion above regarding what the default value should be and the consensus seemed to be that there shouldn't be any (aka "normal"). My preference would be "lax" like Play2 so without thinking there is some automatic protection - this is what "lax" was designed to be, a reasonable compromise that in most cases won't break anything. I realise this means people will need to consider carefully before upgrading to a version with this fix but I think in respect to security that is only a good thing and certainly clear warnings should be provided. Possibly this is a bit academic now because looking at Mozilla Developer Network SameSite, the spec has been updated such that not specifying SameSite is regarded as "lax" in any case.

On a code formatting consistency side, a space between the if and the ( would be nice :)

@asolntsev
Copy link
Contributor

@tazmaniax if I am not mistaken, modern browsers behave like "lax" by default. If it's true, it's good enough to leave "SameSite" attribute empty by default.

@tazmaniax
Copy link
Collaborator

tazmaniax commented Jan 5, 2022

@asolntsev right, I think I came to the same conclusion at the end of my last comment 😄

@Alexandermjos
Copy link

@tazmaniax Thank you for the feedback :) I fill fix the space in the next commit.
Should I change lax to default or not? Is there room for further discussions?
Who are the decision makers, and what is the next steps to proceed?

@tazmaniax
Copy link
Collaborator

tazmaniax commented Jan 5, 2022

@Alexandermjos from @asolntsev's point and what I found, I don't think it's necessary to explicitly set the default to "lax" because browsers now just assume "lax" when SameSite is not defined. It would only be useful if there was a browser that didn't support the latest version of the spec but I think this is a very rare case so I think it's good to leave it to what you have now. Thanks!

I believe the final decision maker is @xael-fry but possibly also @asolntsev

Alexandermjos added a commit to Alexandermjos/play1 that referenced this issue Jan 30, 2022
… Enum. Dont set sameSite for ValidationPlugin
@Alexandermjos
Copy link

I have committed some changes which @asolntsev requested 😄
Also added the space before '(' @tazmaniax 👍

@Alexandermjos
Copy link

@xael-fry Any thoughts? 😃

@lebort
Copy link

lebort commented Apr 26, 2022

Any progress on this issue, @xael-fry or @asolntsev? Could the pull request soon be merged, such that the issue can be fixed in an upcoming release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants