I've set a cookie in Scala similar to the following:
val cookies:Seq[Cookie] = new Seq()
val nDaysExpire:Int = 2000
val nSecondsExpire:Int = nDaysExpire * 24 * 60 * 60
val cookie:Cookie = new Cookie(sCookieID, sValue, Option(nSecondsExpire))
cookies = cookies:+ cookie
Ok(views.html.main(sID)).withCookies(cookies:_*)
and then I immediately delete the cookie in JavaScript. I have even deleted the cookie 30 seconds after the page has loaded.
When I reload the page, the Scala code still sees the cookie. But in the JavaScript, the cookie is no where to be found when I call: document.cookie.
What's going on?
According to the docs, the constructor for
Cookie
takes a boolean parameter namedhttpCookie
. The default value istrue
.HttpOnly cookies cannot be seen by javascript. So, if you want to delete your cookie from javascript, try setting this to false.
By Jeff Atwoord in Protecting Your Cookies: HttpOnly