-
Notifications
You must be signed in to change notification settings - Fork 674
GH-1328: Added SameSite support for session cookie. #1369
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
0a8cb43
6d0d0cc
16d7f92
183053a
7f25a12
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,6 +163,10 @@ public static class Cookie implements Serializable { | |
| * See http://www.owasp.org/index.php/HttpOnly | ||
| */ | ||
| public boolean httpOnly = false; | ||
| /** | ||
| * See https://owasp.org/www-community/SameSite | ||
| */ | ||
| public String sameSite; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -707,8 +711,8 @@ public void setContentTypeIfNotSet(String contentType) { | |
| * @param value | ||
| * Cookie value | ||
| */ | ||
| public void setCookie(String name, String value) { | ||
| setCookie(name, value, null, "/", null, false); | ||
| public void setCookie(String name, String value, String sameSite) { | ||
| setCookie(name, value, null, "/", null, false, sameSite); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -730,7 +734,7 @@ public void removeCookie(String name) { | |
| * cookie path | ||
| */ | ||
| public void removeCookie(String name, String path) { | ||
| setCookie(name, "", null, path, 0, false); | ||
| setCookie(name, "", null, path, 0, false, null); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -743,15 +747,15 @@ public void removeCookie(String name, String path) { | |
| * @param duration | ||
| * the cookie duration (Ex: 3d) | ||
| */ | ||
| public void setCookie(String name, String value, String duration) { | ||
| setCookie(name, value, null, "/", Time.parseDuration(duration), false); | ||
| public void setCookie(String name, String value, String duration, String sameSite) { | ||
| setCookie(name, value, null, "/", Time.parseDuration(duration), false, sameSite); | ||
| } | ||
|
|
||
| public void setCookie(String name, String value, String domain, String path, Integer maxAge, boolean secure) { | ||
| setCookie(name, value, domain, path, maxAge, secure, false); | ||
| public void setCookie(String name, String value, String domain, String path, Integer maxAge, boolean secure, String sameSite) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest using enum instead of String.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I can look into this.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated PR |
||
| setCookie(name, value, domain, path, maxAge, secure, false, sameSite); | ||
| } | ||
|
|
||
| public void setCookie(String name, String value, String domain, String path, Integer maxAge, boolean secure, boolean httpOnly) { | ||
| public void setCookie(String name, String value, String domain, String path, Integer maxAge, boolean secure, boolean httpOnly, String sameSite) { | ||
| path = Play.ctxPath + path; | ||
| if (cookies.containsKey(name) && cookies.get(name).path.equals(path) | ||
| && ((cookies.get(name).domain == null && domain == null) || (cookies.get(name).domain.equals(domain)))) { | ||
|
|
@@ -765,6 +769,7 @@ public void setCookie(String name, String value, String domain, String path, Int | |
| cookie.path = path; | ||
| cookie.secure = secure; | ||
| cookie.httpOnly = httpOnly; | ||
| cookie.sameSite = sameSite; | ||
| if (domain != null) { | ||
| cookie.domain = domain; | ||
| } else { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ public class Scope { | |
| .equals("true"); | ||
| public static boolean SESSION_SEND_ONLY_IF_CHANGED = Play.configuration | ||
| .getProperty("application.session.sendOnlyIfChanged", "false").toLowerCase().equals("true"); | ||
| public static final String SESSION_SAMESITE = Play.configuration.getProperty("application.session.sameSite"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about renaming it to "application.session.cookie.sameSite"?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Sure, I can do that.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated PR |
||
|
|
||
| public static SessionStore sessionStore = createSessionStore(); | ||
|
|
||
|
|
@@ -78,13 +79,13 @@ void save() { | |
| } | ||
| if (out.isEmpty()) { | ||
| if (Http.Request.current().cookies.containsKey(COOKIE_PREFIX + "_FLASH") || !SESSION_SEND_ONLY_IF_CHANGED) { | ||
| Http.Response.current().setCookie(COOKIE_PREFIX + "_FLASH", "", null, "/", 0, COOKIE_SECURE, SESSION_HTTPONLY); | ||
| Http.Response.current().setCookie(COOKIE_PREFIX + "_FLASH", "", null, "/", 0, COOKIE_SECURE, SESSION_HTTPONLY, SESSION_SAMESITE); | ||
| } | ||
| return; | ||
| } | ||
| try { | ||
| String flashData = CookieDataCodec.encode(out); | ||
| Http.Response.current().setCookie(COOKIE_PREFIX + "_FLASH", flashData, null, "/", null, COOKIE_SECURE, SESSION_HTTPONLY); | ||
| Http.Response.current().setCookie(COOKIE_PREFIX + "_FLASH", flashData, null, "/", null, COOKIE_SECURE, SESSION_HTTPONLY, SESSION_SAMESITE); | ||
| } catch (Exception e) { | ||
| throw new UnexpectedException("Flash serializationProblem", e); | ||
| } | ||
|
|
||
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.
Isn't it strange that we use SameSite setting which was introduced for session cookie also for some other cookies?
Uh oh!
There was an error while loading. Please reload this page.
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.
@asolntsev Maybe, idk. What do you suggest? null / ""?
It uses the same settings as session cookie for httpOnly and Secure, so I thought that it should also use same settings as session for samesite.
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.
Updated PR