Fix CSRF failure behind a TLS-terminating reverse proxy
Django had no CSRF_TRUSTED_ORIGINS and no SECURE_PROXY_SSL_HEADER, so it always treated requests as plain HTTP. Login over HTTPS behind Apache/Nginx failed CSRF verification as a result.
This commit is contained in:
parent
f7dd98f6e5
commit
d458cd3673
1 changed files with 6 additions and 0 deletions
|
|
@ -9,6 +9,12 @@ SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "dev-only-change-me")
|
||||||
DEBUG = os.environ.get("DJANGO_DEBUG", "1").lower() in {"1", "true", "yes", "on"}
|
DEBUG = os.environ.get("DJANGO_DEBUG", "1").lower() in {"1", "true", "yes", "on"}
|
||||||
ALLOWED_HOSTS = [host.strip() for host in os.environ.get("DJANGO_ALLOWED_HOSTS", "*").split(",") if host.strip()]
|
ALLOWED_HOSTS = [host.strip() for host in os.environ.get("DJANGO_ALLOWED_HOSTS", "*").split(",") if host.strip()]
|
||||||
|
|
||||||
|
# Needed when running behind a TLS-terminating reverse proxy (Apache/Nginx/etc.):
|
||||||
|
# Django otherwise thinks every request is plain HTTP, which breaks CSRF checks
|
||||||
|
# on login/POST. The proxy must forward X-Forwarded-Proto: https.
|
||||||
|
CSRF_TRUSTED_ORIGINS = [origin.strip() for origin in os.environ.get("DJANGO_CSRF_TRUSTED_ORIGINS", "").split(",") if origin.strip()]
|
||||||
|
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
|
||||||
|
|
||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
"django.contrib.admin",
|
"django.contrib.admin",
|
||||||
"django.contrib.auth",
|
"django.contrib.auth",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue