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

Cookie.DiscardingCookie is not setting sameSite value #10122

Closed
barathguna opened this issue Mar 11, 2020 · 6 comments · Fixed by #10693
Closed

Cookie.DiscardingCookie is not setting sameSite value #10122

barathguna opened this issue Mar 11, 2020 · 6 comments · Fixed by #10693
Milestone

Comments

@barathguna
Copy link

barathguna commented Mar 11, 2020

Issue

When Session is cleared using withNewSession or data map is empty in Session then the play_framework code applies DiscardingCookie which reset the PLAY_SESSION.
But DiscardingCookie is not using sameSite settings. So the set-cookie is ignored by browser.

Play Version

2.7.4

API

DiscardingCookie()

Operating System

Any

JDK

Any

Library Dependencies

NA

Expected Behavior

  1. DiscardingCookie should use sameSite settings
  2. This is applicable only when Session.isEmpty is true

Actual Behavior

  1. sameSite settings is not applied when Session data map is empty

Reproducible Test Case

def clearSession: Action[AnyContent] = Action.async { _ =>
  Future.successful(Ok.withNewSession)
}
@mkurz
Copy link
Member

mkurz commented May 18, 2020

But DiscardingCookie is not using sameSite settings. So the set-cookie is ignored by browser.

You are correct that DiscardingCookie does not set the SameSite flag, however the set-cookie works fine in latest Chrome and Firefox anyway. To unset a cookie, the SameSite flag does not matter.. I can not see any issues here. Which browser are you using? Maybe you got confused in the browser dev tools, Chrome still shows the cookie after the page, which comes with the response that un-sets the cookie, got loaded. Only after you navigate away from that page Chrome updates and shows that the cookie is gone. Firefox is more clear here, it already doesn't show the cookie anymore as soon as the unset cookie response arrives.

@wadouk
Copy link

wadouk commented Oct 26, 2020

The unwanted behavior that is you are still login because of missing the SameSite flag, the modification of the cookie is refused is still served by chrome

Capture d’écran_2020-10-26_11-20-16

Any workaround ?

@mkurz mkurz added this to the 2.8.4 milestone Oct 26, 2020
@mkurz
Copy link
Member

mkurz commented Oct 26, 2020

I am adding this issue to the 2.8.4 milestone, maybe I find time to look into it.

@ignasi35 ignasi35 modified the milestones: 2.8.4, 2.8.5, 2.8.6 Nov 4, 2020
@ennru ennru modified the milestones: 2.8.6, 2.8.7, 2.8.8 Dec 9, 2020
@mkurz
Copy link
Member

mkurz commented Feb 8, 2021

I am not sure why but there was a comment from @wadouk which got deleted (by @wadouk? Or was there a problem with GitHub?)

From my email inbox:

This missing feature exists only in cross domain, so we need to override the domain part for an other closed use case

Our workaround

class XDomainCookieFilter(implicit val mat: Materializer) extends Filter {
	override def apply(nextFilter: (RequestHeader) => Future[Result])(rh: RequestHeader): Future[Result] = {
		val h = rh.host.split("\\.").toList
		val domain = if(h.size < 2) rh.host else s".${h.init.last}.${h.last}"

		val sessionCookie = rh.attrs.get(RequestAttrKey.Cookies).toList.flatMap { _.value.map { c => c.copy(domain = Some(domain)) } }

		nextFilter(rh).map { _.withCookies(sessionCookie: _*).withNewSession }
	}
}

@mkurz mkurz modified the milestones: 2.8.8, 2.9.0 Feb 8, 2021
@mkurz
Copy link
Member

mkurz commented Feb 8, 2021

A possible fix is here: #10693

@wadouk
Copy link

wadouk commented Feb 9, 2021

Don't remember ...
Don't find in the code. Maybe an architecture workaround that set useless this : handling multiple domains in the same app.

@mergify mergify bot closed this as completed in #10693 Apr 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants