Fix CSRF behind Nginx by configuring trusted origins via environment.

Reads CSRF_TRUSTED_ORIGINS and USE_HTTPS from env so admin login works correctly behind HTTPS reverse proxies.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Pirmin Hinderling (fedora)
2026-07-07 19:49:41 +02:00
parent db3558872e
commit ae71704cc5
3 changed files with 23 additions and 7 deletions
+12
View File
@@ -35,6 +35,18 @@ ALLOWED_HOSTS = [
if host.strip()
]
CSRF_TRUSTED_ORIGINS = [
origin.strip()
for origin in os.environ.get('CSRF_TRUSTED_ORIGINS', '').split(',')
if origin.strip()
]
USE_HTTPS = os.environ.get('USE_HTTPS', '').lower() in ('true', '1', 'yes')
if USE_HTTPS:
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
CSRF_COOKIE_SECURE = True
SESSION_COOKIE_SECURE = True
# Application definition