django-secure
django-secure copied to clipboard
This project was merged into Django 1.8, and is now unsupported and unmaintained as a third-party app.
============= django-secure
.. warning::
This project was merged into Django 1.8_. It does not provide any
additional checks beyond those included in Django 1.8+, so there is no
reason to use it with Django 1.8+. Since Django 1.8 is now the lowest
supported Django version, this project is now unsupported and un-maintained.
Helping you remember to do the stupid little things to improve your Django site's security.
Inspired by Mozilla's Secure Coding Guidelines_, and intended for sites that
are entirely or mostly served over SSL (which should include anything with
user logins).
.. _Secure Coding Guidelines: https://wiki.mozilla.org/WebAppSec/Secure_Coding_Guidelines .. _merged into Django 1.8: https://docs.djangoproject.com/en/1.8/releases/1.8/#security-enhancements
Quickstart
Dependencies
Tested with Django_ 1.4 through trunk, and Python_ 2.6, 2.7, 3.2, and
3.3. Quite likely works with older versions of both, though; it's not very
complicated.
.. _Django: http://www.djangoproject.com/ .. _Python: http://www.python.org/
Installation
Install from PyPI with pip::
pip install django-secure
or get the in-development version_::
pip install django-secure==dev
.. _in-development version: https://github.com/carljm/django-secure/tarball/master#egg=django_secure-dev
Usage
-
Add
"djangosecure"to yourINSTALLED_APPSsetting. -
Add
"djangosecure.middleware.SecurityMiddleware"to yourMIDDLEWARE_CLASSESsetting (where depends on your other middlewares, but near the beginning of the list is probably a good choice). -
Set the
SECURE_SSL_REDIRECTsetting toTrueif all non-SSL requests should be permanently redirected to SSL. -
Set the
SECURE_HSTS_SECONDSsetting to an integer number of seconds andSECURE_HSTS_INCLUDE_SUBDOMAINStoTrue, if you want to useHTTP Strict Transport Security_. -
Set the
SECURE_FRAME_DENYsetting toTrue, if you want to prevent framing of your pages and protect them fromclickjacking_. -
Set the
SECURE_CONTENT_TYPE_NOSNIFFsetting toTrue, if you want to prevent the browser from guessing asset content types. -
Set the
SECURE_BROWSER_XSS_FILTERsetting toTrue, if you want to enable the browser's XSS filtering protections. -
Set
SESSION_COOKIE_SECUREandSESSION_COOKIE_HTTPONLYtoTrueif you are usingdjango.contrib.sessions. These settings are not part ofdjango-secure, but they should be used if running a secure site, and thechecksecuremanagement command will check their values. -
Ensure that you're using a long, random and unique
SECRET_KEY. -
Run
python manage.py checksecureto verify that your settings are properly configured for serving a secure SSL site.
.. _HTTP Strict Transport Security: http://en.wikipedia.org/wiki/Strict_Transport_Security
.. _clickjacking: http://www.sectheory.com/clickjacking.htm
.. warning::
If checksecure gives you the all-clear, all it means is that you're now
taking advantage of a small selection of easy security wins. That's great,
but it doesn't mean your site or your codebase is secure: only a competent
security audit can tell you that.
.. end-here
Documentation
See the full documentation_ for more details.
.. _full documentation: http://django-secure.readthedocs.org