Skip to content

Commit b69d45d

Browse files
authored
Merge pull request #439 from NHSDigital/fix-csrf-protection-on-review-app
Fix CSRF protection on review app
2 parents 015fbb9 + e5279fd commit b69d45d

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

infrastructure/environments/dev/variables.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ BASE_URL: https://dev.manage-breast-screening.non-live.screening.nhs.uk
22
BASIC_AUTH_ENABLED: True
33
CIS2_SERVER_METADATA_URL: https://am.nhsint.auth-ptl.cis2.spineservices.nhs.uk/openam/oauth2/realms/root/realms/NHSIdentity/realms/Healthcare/.well-known/openid-configuration
44
PERSONAS_ENABLED: 1
5+
CSRF_TRUSTED_ORIGINS: 'https://dev.manage-breast-screening.non-live.screening.nhs.uk'

infrastructure/environments/preprod/variables.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ BASE_URL: https://preprod.manage-breast-screening.screening.nhs.uk
22
BASIC_AUTH_ENABLED: True
33
CIS2_SERVER_METADATA_URL: https://am.nhsint.auth-ptl.cis2.spineservices.nhs.uk/openam/oauth2/realms/root/realms/NHSIdentity/realms/Healthcare/.well-known/openid-configuration
44
PERSONAS_ENABLED: 1
5+
CSRF_TRUSTED_ORIGINS: 'https://preprod.manage-breast-screening.screening.nhs.uk'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
PERSONAS_ENABLED: 1
2+
CSRF_TRUSTED_ORIGINS: 'https://*.manage-breast-screening.non-live.screening.nhs.uk'

manage_breast_screening/config/settings.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ def boolean_env(key, default=None):
2323
return default if value is None else value in ("True", "true", "1")
2424

2525

26+
def list_env(key):
27+
value = environ.get(key)
28+
return value.split(",") if value else []
29+
30+
2631
# Build paths inside the project like this: BASE_DIR / 'subdir'.
2732
BASE_DIR = Path(__file__).resolve().parent.parent
2833

@@ -38,8 +43,8 @@ def boolean_env(key, default=None):
3843
# SECURITY WARNING: don't run with debug turned on in production!
3944
DEBUG = boolean_env("DEBUG", default=False)
4045

41-
allowed_hosts = environ.get("ALLOWED_HOSTS")
42-
ALLOWED_HOSTS = allowed_hosts.split(",") if allowed_hosts else []
46+
ALLOWED_HOSTS = list_env("ALLOWED_HOSTS")
47+
CSRF_TRUSTED_ORIGINS = list_env("CSRF_TRUSTED_ORIGINS")
4348

4449
allowed_hosts_except_localhost = set(ALLOWED_HOSTS) - {"localhost", "127.0.0.1"}
4550

0 commit comments

Comments
 (0)