Skip to content

Commit 05f96ef

Browse files
author
Obada Haddad
committed
fix csrf and domain_name when the instance is behind multiple different domain names
1 parent ed2b43a commit 05f96ef

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

src/settings/base.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@
1919
csrf_https_domain = "https://" + os.environ.get("DOMAIN_NAME").split(':')[0]
2020
csrf_http_domain = "http://" + os.environ.get("DOMAIN_NAME").split(':')[0]
2121

22-
CSRF_TRUSTED_ORIGINS = [csrf_https_domain, csrf_http_domain]
23-
CSRF_ALLOWED_ORIGINS = [csrf_https_domain, csrf_http_domain]
22+
if os.environ.get("EXTERNAL_DOMAIN_NAME", "") != "":
23+
csrf_https_external_domain = "https://" + os.environ.get("EXTERNAL_DOMAIN_NAME", "").split(':')[0]
24+
csrf_http_external_domain = "http://" + os.environ.get("EXTERNAL_DOMAIN_NAME", "").split(':')[0]
25+
CSRF_TRUSTED_ORIGINS = [csrf_https_domain, csrf_http_domain, csrf_https_external_domain, csrf_http_external_domain]
26+
CSRF_ALLOWED_ORIGINS = [csrf_https_domain, csrf_http_domain, csrf_https_external_domain, csrf_http_external_domain]
2427

25-
SITE_ID = 1
28+
DOMAIN_NAME = os.environ.get('EXTERNAL_DOMAIN_NAME').split(':')[0]
29+
else:
30+
CSRF_TRUSTED_ORIGINS = [csrf_https_domain, csrf_http_domain]
31+
CSRF_ALLOWED_ORIGINS = [csrf_https_domain, csrf_http_domain]
2632

27-
SITE_DOMAIN = os.environ.get('SITE_DOMAIN', 'http://localhost')
28-
DOMAIN_NAME = os.environ.get('DOMAIN_NAME', 'localhost').split(':')[0]
33+
DOMAIN_NAME = os.environ.get('DOMAIN_NAME', 'localhost').split(':')[0]
2934

30-
SELENIUM_HOSTNAME = os.environ.get("SELENIUM_HOSTNAME", "localhost")
35+
SITE_DOMAIN = os.environ.get('SITE_DOMAIN', 'http://localhost')
36+
SITE_ID = 1
3137

3238

3339
THIRD_PARTY_APPS = (

0 commit comments

Comments
 (0)