proxy headers

This commit is contained in:
2026-10-23 18:38:48 +02:00
parent 2c4dac628e
commit 6e7a68d509
2 changed files with 22 additions and 0 deletions
@@ -64,6 +64,26 @@ ALLOWED_HOSTS = [
if host
]
# TLS is terminated by the reverse proxy in front of the container, so daphne
# only ever sees plain http. Without these, Django compares the browser's
# `Origin: https://...` against `http://...` and rejects every POST (admin
# login included) with "CSRF verification failed - Origin checking failed".
# Full origins with scheme, e.g. "https://submitter.polylan.ch".
CSRF_TRUSTED_ORIGINS = [
origin
for origin in (os.environ.get("DJANGO_CSRF_TRUSTED_ORIGINS") or "").split(",")
if origin
]
# Trust the proxy's X-Forwarded-Proto so request.is_secure() /
# build_absolute_uri() report https. Only safe if the proxy overwrites that
# header (client-supplied values must not pass through) - opt-in for that
# reason.
if os.environ.get("DJANGO_BEHIND_TLS_PROXY", "false").lower() == "true":
SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
# Application definition