Skip to content

Commit

Permalink
Use commonware.response.cookies to enable secure and httponly cookies…
Browse files Browse the repository at this point in the history
… by default. Closes Issue 3.
  • Loading branch information
Fred Wenzel committed Jan 22, 2011
1 parent 84b3cbf commit b476dd2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
19 changes: 18 additions & 1 deletion docs/bestpractices.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,21 @@ following works as expected::

Mmmmh, Cookies
--------------
Om nom nom. Also: Issue 3.

Django's default way of setting a cookie is set_cookie_ on the HTTP response.
Unfortunately, both **secure** cookies (i.e., HTTPS-only) and **httponly**
(i.e., cookies not readable by JavaScript, if the browser supports it) are
disabled by default.

To be secure by default, we use commonware's ``cookies`` app. It makes secure
and httponly cookies the default, unless specifically requested otherwise.

To disable either of these patches, set ``COOKIES_SECURE = False`` or
``COOKIES_HTTPONLY = False`` in ``settings.py``.

You can exempt every cookie by passing ``secure=False`` or ``httponly=False``
to the ``set_cookie`` call, respectively::

response.set_cookie('hello', value='world', secure=False, httponly=False)

.. _set_cookie: http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpResponse.set_cookie
1 change: 1 addition & 0 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def JINJA_CONFIG():
ROOT_PACKAGE,

# Third-party apps
'commonware.response.cookies',
'djcelery',
'django_nose',

Expand Down
2 changes: 1 addition & 1 deletion vendor
Submodule vendor updated 2569 files

0 comments on commit b476dd2

Please sign in to comment.