Commit 65882e59 authored by Jérome Perrin's avatar Jérome Perrin

core: set SameSite=Lax on authentication cookie

https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-02

We choose Lax and not Strict so that we can open links to ERP5 from
external applications and so that OAuth Logins work. Implementing the
"two cookies, one for read one for write" approach suggested in
https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-02#section-8.8.2
would be too big change at this point.
parent ee05c9c4
......@@ -121,6 +121,7 @@ class TestFacebookLogin(ERP5TypeTestCase):
ac_cookie, = [v for (k, v) in response.listHeaders() if k.lower() == 'set-cookie' and '__ac_facebook_hash=' in v]
self.assertIn('; Secure', ac_cookie)
self.assertIn('; HTTPOnly', ac_cookie)
self.assertIn('; SameSite=Lax', ac_cookie)
def test_create_user_in_ERP5Site_createFacebookUserToOAuth(self):
"""
......
......@@ -158,6 +158,7 @@ class TestGoogleLogin(ERP5TypeTestCase):
ac_cookie, = [v for (k, v) in response.listHeaders() if k.lower() == 'set-cookie' and '__ac_google_hash=' in v]
self.assertIn('; Secure', ac_cookie)
self.assertIn('; HTTPOnly', ac_cookie)
self.assertIn('; SameSite=Lax', ac_cookie)
def test_create_user_in_ERP5Site_createGoogleUserToOAuth(self):
"""
......
......@@ -21,5 +21,6 @@ resp.setCookie(
path='/',
secure=getattr(portal, 'REQUEST', {}).get('SERVER_URL', '').startswith('https:'),
http_only=True,
same_site='Lax',
**kw
)
......@@ -1301,6 +1301,11 @@ class TestAuthenticationCookie(UserManagementTestCase):
# HTTPOnly flag so that javascript cannot access cookie
self.assertIn('; HTTPOnly', ac_cookie)
# SameSite=Lax flag so that cookie is not sent on cross origin requests.
# We set Lax (and not strict) so that opening a link to ERP5 from an
# external site does not prompt for login.
self.assertIn('; SameSite=Lax', ac_cookie)
class TestReindexObjectSecurity(UserManagementTestCase):
def afterSetUp(self):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment