SameSite cookie in Java application

后端 未结 9 2005
没有蜡笔的小新
没有蜡笔的小新 2020-12-24 01:08

Do you know any Java cookie implementation which allows to set a custom flag for cookie, like SameSite=strict? It seems that javax.servlet.http.Cookie has a str

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-24 01:23

    I tried the listed solutions for using javax.servlet.http.Cookie to set the SameSite=strict attribute, but none of them worked.

    However, this way worked for me, using javax.servlet.http.Cookie (JRE 1.8 + JBOSS 7.X) :

    Cookie cookie = new Cookie(name, value);
    path = path.concat("SameSite=Strict;");
    cookie.setPath(path);
    

    That's it. tested on

    • Google Chrome Version 81.0.4044.129 (Official Build) (64-bit)
    • Microsoft Edge Version 81.0.416.68 (Official build) (64-bit)
    • Firefox 75.0 (64-bit)

提交回复
热议问题