Skip to content

Commit

Permalink
csrf fix behind proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
ansibleguy committed Feb 15, 2024
1 parent 307386f commit 5e22eea
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/ansible-webui/aw/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
]

DEBUG = deployment_dev()
ALLOWED_HOSTS = ['*']
DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'
X_FRAME_OPTIONS = 'SAMEORIGIN'

Expand Down Expand Up @@ -58,15 +57,22 @@
]
if 'AW_PROXY' in environ:
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
USE_X_FORWARDED_HOST = True

ALLOWED_HOSTS = ['*']
if 'AW_HOSTNAMES' in environ:
for hostname in environ['AW_HOSTNAMES'].split(','):
ALLOWED_HOSTS.append(hostname)
CSRF_TRUSTED_ORIGINS.extend([
f'http://{hostname}', f'https://{hostname}',
f'http://{hostname}:{PORT_WEB}', f'https://{hostname}:{PORT_WEB}',
f'http://{hostname}',
f'https://{hostname}',
f'http://{hostname}:{PORT_WEB}',
f'https://{hostname}:{PORT_WEB}',
])

CSRF_ALLOWED_ORIGINS = CSRF_TRUSTED_ORIGINS
CORS_ORIGINS_WHITELIST = CSRF_TRUSTED_ORIGINS

ROOT_URLCONF = 'aw.urls'
TEMPLATES = [
{
Expand Down

0 comments on commit 5e22eea

Please sign in to comment.