Django

Code

Ticket #6657 (closed: fixed)

Opened 9 months ago

Last modified 9 months ago

HttpResponse.set_cookie(secure=False) still sets secure cookies

Reported by: Gulopine Assigned to: nobody
Milestone: Component: HTTP handling
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

Currently, set_cookie() sets the secure attribute on the outgoing cookie if it's anything other than None, but since the secure attribute on cookies doesn't actually use a value, it gets sent out as secure any time any value is set on the cookie. This means that using secure=False results in a secure cookie. While it's still possible to set a non-secure cookie by simply omitting the secure argument entirely, the current behavior seems counter-intuitive.

>>> from django.http import HttpResponse
>>> response = HttpResponse()
>>> response.set_cookie('a')
>>> response.set_cookie('b', secure=False)
>>> response.set_cookie('c', secure=True)
>>> print response.cookies
Set-Cookie: a=; Path=/
Set-Cookie; b=; Path=/; secure
Set-Cookie; c=; Path=/; secure

Attachments

set_cookie.diff (1.3 kB) - added by Gulopine on 02/24/08 20:07:04.
Changed set_cookie() to take secure=False and to only set it on the cookie if it evaluates to True

Change History

02/24/08 20:07:04 changed by Gulopine

  • attachment set_cookie.diff added.

Changed set_cookie() to take secure=False and to only set it on the cookie if it evaluates to True

02/24/08 21:19:01 changed by mtredinnick

  • needs_better_patch changed.
  • stage changed from Unreviewed to Ready for checkin.
  • needs_tests changed.
  • needs_docs changed.

Does more than is necessary, but the rewrite is useful, too. Removing that replace() call just for the benefit of max-age isn't bad and we aren't going to be adding another 10 parameters here anytime soon, so the scaling of all the if-blocks isn't an issue.

03/07/08 21:31:43 changed by gwilson

  • status changed from new to closed.
  • resolution set to fixed.

(In [7204]) Fixed #6657 -- Don't set secure attribute on cookie if secure=False is passed, thanks Gulopine.


Add/Change #6657 (HttpResponse.set_cookie(secure=False) still sets secure cookies)




Change Properties
Action