-
Notifications
You must be signed in to change notification settings - Fork 41.2k
Add support for omitting the SameSite attribute from the session cookie #44714
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
Conversation
eca72bd
to
3d808be
Compare
/** | ||
* Don't set the SameSite cookie attribute. | ||
*/ | ||
UNSET("Unset"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may just be me, but UNSET
makes me have to stop and think to understand what it does. I wonder if OMITTED
, described as "The SameSite cookie attribute is omitted" would be clearer?
Also, could the attribute value be null
? I wonder if that would simplify the logic for applying it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if
OMITTED
, described as "The SameSite cookie attribute is omitted" would be clearer?
You are fully right @wilkinsona. OMITTED
is extremely clear. I'll look into it tomorrow.
Also, could the attribute value be
null
? I wonder if that would simplify the logic for applying it.
I'll check that tomorrow, I had an idea to use null
, but not sure why I didn't do it in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember now why I picked UNSET
, it's because the enum org.apache.tomcat.util.http.SameSiteCookies
has it. In any case OMITTED
is more clear so I'll go ahead and use that
Signed-off-by: Filip Hrisafov <filip.hrisafov@gmail.com>
Signed-off-by: Filip Hrisafov <filip.hrisafov@gmail.com>
Signed-off-by: Filip Hrisafov <filip.hrisafov@gmail.com>
b7424f3
to
cd51c80
Compare
Thanks for the review @wilkinsona. I've changed the name and tried using |
See gh-44714 Signed-off-by: Filip Hrisafov <filip.hrisafov@gmail.com>
Thanks very much, @filiphr. |
Thanks for the quick integration @wilkinsona |
@filiphr are you sure it wasn't possible to solve the issue you're having using this combination of properties: server.servlet.session.cookie.same-site=none
server.servlet.session.cookie.secure=true I distinctly remember one of the teams in organization I'm working with having what looks like the same issue, and we were able to solve it this way. It's been a while since I looked at SameSite at depth, but resources like this one still mention Also see this StackOverflow answer: https://stackoverflow.com/a/72652458/3944191 |
I didn't try that combination @vpavic. I did try with:
However, that was not working. I was also reading and it was saying that if
That's the StackOverflow answer I also referenced in my initial issue. That's where I found @Bean
public DefaultCookieSerializerCustomizer disableSameSite() {
return cookieSerializer -> cookieSerializer.setSameSite(null);
} I was also comparing the Tomcat |
From what I can see your issue description links to different SO question, but that's not so important as both SO questions we linked mention the same thing as the article about SameSite I also linked to in previous comment:
I personally wouldn't rely on unspecified behavior that might change in future without notice. |
You are right, I saw it incorrectly.
I am not sure that I understand. This is not about using Reading the article you shared (https://web.dev/articles/samesite-cookies-explained) again, it indeed looks like the combination of
should be enough. I'll need to test this for our scenario to validate this fully. |
If you read the article I shared, it says that Cookies without a SameSite attribute are treated as SameSite=Lax. From your description, sounds like you're relying on browser behavior that's different from that and is what I refer to as unspecified behavior that might change in the future. There's also a sentence about that at the end of SO answer I linked. |
The main reason for this pull request is to make it easier to disable setting the SameSite cookie in the Spring Session
CookieSerializer
. The default for the Spring Session is Lax. However, this does not work when using SAML with POST redirect, when the cookie is Lax, then the session cookie will not be sent when the redirect happens and thus the authentication will not work (see https://stackoverflow.com/questions/60068271/samesite-attribute-break-saml-flow/60096206#60096206 and https://www.linkedin.com/pulse/samesite-cookie-infinite-redirections-saml-digvijay-singh/).The current workaround I have is to expose the following bean
i.e. use the serializer to disable the cookie.
If this PR is accepted it would make it easier to configure this without the need to expose a bean by just doing
server.servlet.session.cookie.same-site=unset