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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user