I'm setting up site-wide HTTPS for my Django 1.8 project. I am not experienced in web security.
I'm setting up HTTP to HTTPS redirect and HSTS.
Right now, I was configuring this on my Apache/mod_wsgi Web Server (I'm using a PaaS so I configure it through the .htaccess file on the WSGI root):
wsgi/.htaccess
# Redirect HTTP to HTTPS
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
# Add HSTS header
Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"
# Deny rendering inside an iframe
Header always set X-Frame-Options DENY
As per the Django official docs SSL recommendations, I'm securing the cookies in my production settings:
settings/prod.py
...
SESSION_COOKIE_SECURE = True
CSRF_COOKIE_SECURE = True
...
Note: I'm not setting SECURE_PROXY_SSL_HEADER = (“HTTP_X_FORWARDED_PROTO”, “https”)
yet, because I'm not sure yet if the PaaS is proxying and stripping this header between the proxy and the web container.
Django (as of 1.8) now comes with it's security middleware(from old django-secure), which implements SSL redirects, and handles HSTS header and other nice things.
Should I let Django handle all of the HTTPS redirect/HSTS configurations, or do it at the web server level? What are the security/performance implications of each choice?
References read/used:
https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security
https://garron.net/crypto/hsts/hsts-2013.pdf
https://cipherli.st/
https://mozilla.github.io/server-side-tls/ssl-config-generator/
https://security.stackexchange.com/questions/8964/trying-to-make-a-django-based-site-use-https-only-not-sure-if-its-secure
http://www.marinamele.com/2014/09/security-on-django-app-https-everywhere.html
https://raymii.org/s/tutorials/HTTP_Strict_Transport_Security_for_Apache_NGINX_and_Lighttpd.html
https://docs.djangoproject.com/en/1.8/topics/security/