Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions liberapay/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,14 @@ def _assert(x):
]


# Monkey patch python's stdlib
# ============================

from six.moves.http_cookies import Morsel

Morsel._reserved[str('samesite')] = str('SameSite')


# Monkey patch aspen and pando
# ============================

Expand Down
4 changes: 3 additions & 1 deletion liberapay/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ def ensure_str(s):
return s.decode('ascii') if isinstance(s, bytes) else s.encode('ascii')


def set_cookie(cookies, key, value, expires=None, httponly=True, path='/'):
def set_cookie(cookies, key, value, expires=None, httponly=True, path='/', samesite='lax'):
key = ensure_str(key)
cookies[key] = ensure_str(value)
cookie = cookies[key]
Expand All @@ -300,6 +300,8 @@ def set_cookie(cookies, key, value, expires=None, httponly=True, path='/'):
cookie[str('httponly')] = True
if path:
cookie[str('path')] = ensure_str(path)
if samesite:
cookie[str('samesite')] = ensure_str(samesite)
if website.cookie_domain:
cookie[str('domain')] = ensure_str(website.cookie_domain)
if website.canonical_scheme == 'https':
Expand Down
1 change: 1 addition & 0 deletions tests/py/test_state_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def test_csrf_cookie_properties(self):
assert cookie[str('expires')][-4:] == str(' GMT')
assert cookie[str('path')] == str('/')
assert cookie[str('secure')] is True
assert cookie[str('samesite')] == str('lax')


class Tests2(Harness):
Expand Down