Skip to content

Commit 4712e83

Browse files
committed
Added a patch to make django use the same settings when deleting a cookie as when setting it. In particular, it sets Secure if settings.SESSION_COOKIE_SECURE, which is needed if samesite='None'. Fixes issue ietf-tools#3056
- Legacy-Id: 18359
1 parent 07d60de commit 4712e83

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

ietf/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,7 @@ def skip_unreadable_post(record):
11361136
'patch/fix-oic-logging.patch',
11371137
'patch/fix-django-password-strength-kwargs.patch',
11381138
'patch/add-django-http-cookie-value-none.patch',
1139+
'patch/django-cookie-delete-with-all-settings.patch',
11391140
]
11401141
if DEBUG:
11411142
try:
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--- django/contrib/messages/storage/cookie.py.orig 2020-08-13 11:10:36.719177122 +0200
2+
+++ django/contrib/messages/storage/cookie.py 2020-08-13 11:45:23.503463150 +0200
3+
@@ -92,6 +92,8 @@
4+
response.delete_cookie(
5+
self.cookie_name,
6+
domain=settings.SESSION_COOKIE_DOMAIN,
7+
+ secure=settings.SESSION_COOKIE_SECURE or None,
8+
+ httponly=settings.SESSION_COOKIE_HTTPONLY or None,
9+
samesite=settings.SESSION_COOKIE_SAMESITE,
10+
)
11+
12+
--- django/http/response.py.orig 2020-08-13 11:16:04.060627793 +0200
13+
+++ django/http/response.py 2020-08-13 11:54:03.482476973 +0200
14+
@@ -210,12 +210,19 @@
15+
value = signing.get_cookie_signer(salt=key + salt).sign(value)
16+
return self.set_cookie(key, value, **kwargs)
17+
18+
- def delete_cookie(self, key, path='/', domain=None, samesite=None):
19+
+ def delete_cookie(self, key, path='/', domain=None, secure=False, httponly=False, samesite=None):
20+
# Most browsers ignore the Set-Cookie header if the cookie name starts
21+
# with __Host- or __Secure- and the cookie doesn't use the secure flag.
22+
- secure = key.startswith(('__Secure-', '__Host-'))
23+
+ import debug
24+
+ if key in self.cookies:
25+
+ domain = self.cookies[key].get('domain', domain)
26+
+ secure = self.cookies[key].get('secure', secure)
27+
+ httponly = self.cookies[key].get('httponly', httponly)
28+
+ samesite = self.cookies[key].get('samesite', samesite)
29+
+ else:
30+
+ secure = secure or key.startswith(('__Secure-', '__Host-'))
31+
self.set_cookie(
32+
- key, max_age=0, path=path, domain=domain, secure=secure,
33+
+ key, max_age=0, path=path, domain=domain, secure=secure, httponly=httponly,
34+
expires='Thu, 01 Jan 1970 00:00:00 GMT', samesite=samesite,
35+
)
36+
37+
--- django/contrib/sessions/middleware.py.orig 2020-08-13 12:12:12.401898114 +0200
38+
+++ django/contrib/sessions/middleware.py 2020-08-13 12:14:52.690520659 +0200
39+
@@ -39,6 +39,8 @@
40+
settings.SESSION_COOKIE_NAME,
41+
path=settings.SESSION_COOKIE_PATH,
42+
domain=settings.SESSION_COOKIE_DOMAIN,
43+
+ secure=settings.SESSION_COOKIE_SECURE or None,
44+
+ httponly=settings.SESSION_COOKIE_HTTPONLY or None,
45+
samesite=settings.SESSION_COOKIE_SAMESITE,
46+
)
47+
else:

0 commit comments

Comments
 (0)