🔒 Fix CSRF verification failed error for Railway domain

- Add quantum-ai.up.railway.app to CSRF_TRUSTED_ORIGINS
- Include development origins (localhost, 127.0.0.1)
- Improve Railway domain detection with fallback
- Prevent duplicate domain entries

Fixes 403 CSRF verification failed errors on login and admin forms.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Claude 2025-07-26 23:24:38 +05:30
parent 8538b63246
commit d2358fb0bb

View File

@ -296,11 +296,24 @@ EMAIL_TIMEOUT = 30
# Security settings
CSRF_TRUSTED_ORIGINS = [origin.strip() for origin in config('CSRF_TRUSTED_ORIGINS', default='').split(',') if origin.strip()]
# Always include common development origins
CSRF_TRUSTED_ORIGINS.extend([
'http://localhost:8000',
'http://127.0.0.1:8000',
'https://localhost:8000',
'https://127.0.0.1:8000'
])
# Add Railway domain if running on Railway
if config('RAILWAY_ENVIRONMENT', default=''):
# Add known Railway domain
CSRF_TRUSTED_ORIGINS.append('https://quantum-ai.up.railway.app')
# Try to get Railway public domain from environment
railway_url = config('RAILWAY_PUBLIC_DOMAIN', default='')
if railway_url:
if railway_url and f'https://{railway_url}' not in CSRF_TRUSTED_ORIGINS:
CSRF_TRUSTED_ORIGINS.append(f'https://{railway_url}')
# Also add production domain
CSRF_TRUSTED_ORIGINS.append('https://quantumtaskai.com')