[Django] #31790: HttpResponseBase's delete_cookie always sets Samesite to None.

9 views
Skip to first unread message

Django

unread,
Jul 14, 2020, 2:45:03 PM7/14/20
to django-...@googlegroups.com
#31790: HttpResponseBase's delete_cookie always sets Samesite to None.
----------------------------------------+------------------------
Reporter: Gilbreaa | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
We noticed we were getting this warning message from Firefox:

'Cookie “messages” will be soon rejected because it has the “sameSite”
attribute set to “none” or an invalid value, without the “secure”
attribute. To know more about the “sameSite“ attribute, read
[https://developer.mozilla.org/docs/Web/HTTP/Headers/Set-Cookie/SameSite]'

We are getting this from the messages system but it doesn't look like an
issue with the messages app. Here is the cookie header for messages on the
POST:

{{{
Set-Cookie: messages=(... encoded message text ...); HttpOnly; Path=/;
SameSite=Lax
}}}

This has SameSite set. But the POST returns a 304 and the following GET's
cookie header is this:

{{{
Set-Cookie: messages=""; expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0;
Path=/
}}}

This looks like it is just expiring the cookie so the browser will delete
it. As we were digging in to what might be causing this we noticed that
messages is using the response's delete_cookie method to expire the cookie
if there is no message data.

HttpResponseBase's delete_cookie method doesn't seem like it setting the
Samesite setting on Set-Cookie headers. It also is only setting 'Secure'
if the cookie's key begins with '__Secure' or '__Host'. Chrome and Firefox
will soon begin ignoring Set-Cookie headers with Samesite=None that aren't
marked 'Secure'. This could result in Chrome and Firefox ignoring all
cookies deleted through HttpResponseBase's delete_cookie method if the
cookie key does not start with '__Secure' or '__Host'.

For testing I modified delete_cookie to look like this:
{{{
def delete_cookie(self, key, path='/', domain=None):
# Most browsers ignore the Set-Cookie header if the cookie name
starts
# with __Host- or __Secure- and the cookie doesn't use the secure
flag.
self.set_cookie(
key, max_age=0, path=path,
expires='Thu, 01 Jan 1970 00:00:00 GMT',
domain=domain if domain is not None else
settings.SESSION_COOKIE_DOMAIN,
secure=settings.SESSION_COOKIE_SECURE or
key.startswith(('__Secure-', '__Host-')),
httponly=settings.SESSION_COOKIE_HTTPONLY or None,
samesite=settings.SESSION_COOKIE_SAMESITE,
)
}}}
Definitely wouldn't want to use the session cookie settings for everything
but changing this stopped the warnings from coming in on Firefox. I copied
the kwargs from the messages code.

Thought this might be worth a report.

--
Ticket URL: <https://code.djangoproject.com/ticket/31790>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 15, 2020, 6:11:51 AM7/15/20
to django-...@googlegroups.com
#31790: HttpResponse.delete_cookie() should preserve cookie's samesite.
-------------------------------+------------------------------------

Reporter: Gilbreaa | Owner: nobody
Type: Bug | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by felixxm):

* component: Core (Other) => HTTP handling
* version: 2.2 => master
* stage: Unreviewed => Accepted


Comment:

Thanks for this report, IMO we should add the `samesite` argument to
`delete_cookie()` and preserve it for deleted cookies (see related
#30862).

--
Ticket URL: <https://code.djangoproject.com/ticket/31790#comment:1>

Django

unread,
Jul 15, 2020, 6:19:33 AM7/15/20
to django-...@googlegroups.com
#31790: HttpResponse.delete_cookie() should preserve cookie's samesite.
-------------------------------+------------------------------------
Reporter: Gilbreaa | Owner: felixxm
Type: Bug | Status: assigned

Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by felixxm):

* owner: nobody => felixxm
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/31790#comment:2>

Django

unread,
Jul 15, 2020, 6:25:35 AM7/15/20
to django-...@googlegroups.com
#31790: HttpResponse.delete_cookie() should preserve cookie's samesite.
---------------------------------+------------------------------------

Reporter: Gilbreaa | Owner: felixxm
Type: Bug | Status: assigned
Component: HTTP handling | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by felixxm):

* version: master => 3.1
* severity: Normal => Release blocker


--
Ticket URL: <https://code.djangoproject.com/ticket/31790#comment:3>

Django

unread,
Jul 15, 2020, 7:00:34 AM7/15/20
to django-...@googlegroups.com
#31790: HttpResponse.delete_cookie() should preserve cookie's samesite.
---------------------------------+------------------------------------
Reporter: Gilbreaa | Owner: felixxm
Type: Bug | Status: assigned
Component: HTTP handling | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by felixxm):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/13195 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/31790#comment:4>

Django

unread,
Jul 15, 2020, 8:42:23 AM7/15/20
to django-...@googlegroups.com
#31790: HttpResponse.delete_cookie() should preserve cookie's samesite.
-------------------------------------+-------------------------------------

Reporter: Gilbreaa | Owner: felixxm
Type: Bug | Status: assigned
Component: HTTP handling | Version: 3.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31790#comment:5>

Django

unread,
Jul 16, 2020, 2:17:16 AM7/16/20
to django-...@googlegroups.com
#31790: HttpResponse.delete_cookie() should preserve cookie's samesite.
-------------------------------------+-------------------------------------
Reporter: Gilbreaa | Owner: felixxm
Type: Bug | Status: closed

Component: HTTP handling | Version: 3.1
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"240cbb63bf9965c63d7a3cc9032f91410f414d46" 240cbb6]:
{{{
#!CommitTicketReference repository=""
revision="240cbb63bf9965c63d7a3cc9032f91410f414d46"
Fixed #31790 -- Fixed setting SameSite and Secure cookies flags in
HttpResponse.delete_cookie().

Cookies with the "SameSite" flag set to None and without the "secure"
flag will be soon rejected by latest browser versions.

This affects sessions and messages cookies.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31790#comment:6>

Django

unread,
Jul 16, 2020, 2:18:29 AM7/16/20
to django-...@googlegroups.com
#31790: HttpResponse.delete_cookie() should preserve cookie's samesite.
-------------------------------------+-------------------------------------
Reporter: Gilbreaa | Owner: felixxm
Type: Bug | Status: closed
Component: HTTP handling | Version: 3.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"3ca8cc0df14066133321c186758191f33a26a217" 3ca8cc0d]:
{{{
#!CommitTicketReference repository=""
revision="3ca8cc0df14066133321c186758191f33a26a217"
[3.1.x] Fixed #31790 -- Fixed setting SameSite and Secure cookies flags in
HttpResponse.delete_cookie().

Cookies with the "SameSite" flag set to None and without the "secure"
flag will be soon rejected by latest browser versions.

This affects sessions and messages cookies.

Backport of 240cbb63bf9965c63d7a3cc9032f91410f414d46 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31790#comment:7>

Django

unread,
Jul 16, 2020, 3:27:33 AM7/16/20
to django-...@googlegroups.com
#31790: HttpResponse.delete_cookie() should preserve cookie's samesite.
-------------------------------------+-------------------------------------
Reporter: Gilbreaa | Owner: felixxm
Type: Bug | Status: closed
Component: HTTP handling | Version: 3.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"9bc8b1ad2d88209bf45f389fe3cc8b94909b0e72" 9bc8b1ad]:
{{{
#!CommitTicketReference repository=""
revision="9bc8b1ad2d88209bf45f389fe3cc8b94909b0e72"
Refs #31790 -- Removed incorrect item from 2.2.15 and 3.0.9 release notes.

Django 2.2 and 3.0 don't support settings samesite='None' in
HttpResponse.set_cookie() so fix is not necessary and will not be
backported.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31790#comment:8>

Django

unread,
Jul 16, 2020, 3:28:20 AM7/16/20
to django-...@googlegroups.com
#31790: HttpResponse.delete_cookie() should preserve cookie's samesite.
-------------------------------------+-------------------------------------
Reporter: Gilbreaa | Owner: felixxm
Type: Bug | Status: closed
Component: HTTP handling | Version: 3.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"54dce8148ae1d2f662bbc51c4debf8549aaee081" 54dce814]:
{{{
#!CommitTicketReference repository=""
revision="54dce8148ae1d2f662bbc51c4debf8549aaee081"
[3.1.x] Refs #31790 -- Removed incorrect item from 2.2.15 and 3.0.9
release notes.

Django 2.2 and 3.0 don't support settings samesite='None' in
HttpResponse.set_cookie() so fix is not necessary and will not be
backported.

Backport of 9bc8b1ad2d88209bf45f389fe3cc8b94909b0e72 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31790#comment:9>

Django

unread,
Jul 16, 2020, 3:30:39 AM7/16/20
to django-...@googlegroups.com
#31790: HttpResponse.delete_cookie() should preserve cookie's samesite.
-------------------------------------+-------------------------------------
Reporter: Gilbreaa | Owner: felixxm
Type: Bug | Status: closed
Component: HTTP handling | Version: 3.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by GitHub <noreply@…>):

In [changeset:"331324ecce1330dce3dbd1713203cb9a42854ad7" 331324ec]:
{{{
#!CommitTicketReference repository=""
revision="331324ecce1330dce3dbd1713203cb9a42854ad7"
[3.0.x] Fixed #31790 -- Fixed setting SameSite cookies flag in
HttpResponse.delete_cookie().

Cookies with the "SameSite" flag set to None and without the "secure"
flag will be soon rejected by latest browser versions.

This affects sessions and messages cookies.

Backport of 240cbb63bf9965c63d7a3cc9032f91410f414d46 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31790#comment:10>

Django

unread,
Jul 16, 2020, 3:37:25 AM7/16/20
to django-...@googlegroups.com
#31790: HttpResponse.delete_cookie() should preserve cookie's samesite.
-------------------------------------+-------------------------------------
Reporter: Gilbreaa | Owner: felixxm
Type: Bug | Status: closed
Component: HTTP handling | Version: 3.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"f1a6e6c817f3205ea7da6f973f51524ff630dda5" f1a6e6c8]:
{{{
#!CommitTicketReference repository=""
revision="f1a6e6c817f3205ea7da6f973f51524ff630dda5"
[2.2.x] Fixed #31790 -- Fixed setting SameSite cookies flag in
HttpResponse.delete_cookie().

Cookies with the "SameSite" flag set to None and without the "secure"
flag will be soon rejected by latest browser versions.

This affects sessions and messages cookies.

Backport of 331324ecce1330dce3dbd1713203cb9a42854ad7 from stable/3.0.x
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31790#comment:11>

Reply all
Reply to author
Forward
0 new messages