How can I add the flag SameSite=Lax or SameSite=Strict to session cookies generated by Jetty if I am using it to host war files?
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers. The SameSite attribute of the Set-Cookie HTTP response header allows you to declare if your cookie should be restricted to a first-party or same-site context.
Android System WebView To prepare, Android allows native apps to set cookies directly through the CookieManager API. You must declare first party cookies as SameSite=Lax or SameSite=Strict , as appropriate. You must declare third party cookies as SameSite=None; Secure .
Enable the new SameSite behavior If you are running Chrome 91 or newer, you can skip to step 3.) Go to chrome://flags and enable (or set to "Default") both #same-site-by-default-cookies and #cookies-without-same-site-must-be-secure. Restart Chrome for the changes to take effect, if you made any changes.
From spring boot version 2.6. + you may specify your samesite cookie either programatically or via configuration file. This should be the answer for 2022. Upper will cause Spring to bind the attribute into org.
Starting with Jetty 9.4.23, you can specify the desired SameSite value for JSESSIONID cookie set by Jetty in web.xml file of your web app like this:
<session-config>
<cookie-config>
<comment>__SAME_SITE_STRICT__</comment>
</cookie-config>
</session-config>
Other possible values are __SAME_SITE_LAX__
and __SAME_SITE_NONE__
.
See issue #4247 in Jetty for details.
I'm using Jetty 6.1.19 version, As Jetty doesn't support the SameSite attribute in Cookies. Jetty also provided some support/workaround for SameSite its lastest version of Jetty 9.*. I figure out a workaround of Jetty 6.1.19 version I have added the below line of code in Jetty API, Change in method name addSetCookie of class HttpFields. It is worked for me.
buf.append(";SameSite=Strict");
API code:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With