Skip to content

Commit

Permalink
Merge pull request #1308 from jacobdgm/1288-allowed-hosts
Browse files Browse the repository at this point in the history
Ensure CSRF_TRUSTED_ORIGINS and ALLOWED_HOSTS are specified
  • Loading branch information
jacobdgm authored Feb 9, 2024
2 parents 69ae2f5 + deb8910 commit 9a9507e
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions django/cantusdb_project/cantusdb/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.getenv("CANTUSDB_SECRET_KEY")

PROJECT_ENVIRONMENT = os.getenv("PROJECT_ENVIRONMENT")

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = bool(strtobool(os.getenv("CANTUSDB_DEBUG", "False")))
# need to set this to false so that we can display the custom 404 page
DEBUG = False # this is switched to True below when PROJECT_ENVIRONMENT=="DEVELOPMENT"

ALLOWED_HOSTS = [os.getenv("CANTUSDB_HOSTS")]
if PROJECT_ENVIRONMENT == "DEVELOPMENT":
ALLOWED_HOSTS = os.getenv("CANTUSDB_HOSTS_DEVELOPMENT").split(" ")
CSRF_TRUSTED_ORIGINS = os.getenv("CANTUSDB_ORIGINS_DEVELOPMENT").split(" ")
DEBUG = True
if PROJECT_ENVIRONMENT == "STAGING":
ALLOWED_HOSTS = os.getenv("CANTUSDB_HOSTS_STAGING").split(" ")
CSRF_TRUSTED_ORIGINS = os.getenv("CANTUSDB_ORIGINS_STAGING").split(" ")
if PROJECT_ENVIRONMENT == "PRODUCTION":
ALLOWED_HOSTS = os.getenv("CANTUSDB_HOSTS_PRODUCTION").split(" ")
CSRF_TRUSTED_ORIGINS = os.getenv("CANTUSDB_ORIGINS_PRODUCTION").split(" ")


# Application definition
Expand Down Expand Up @@ -200,8 +210,6 @@
"127.0.0.1",
]

CSRF_TRUSTED_ORIGINS = ["https://cantusdatabase.org", "https://www.cantusdatabase.org"]

if DEBUG:
INSTALLED_APPS.append("debug_toolbar")
# debug toolbar must be inserted as early in the middleware as possible
Expand Down

0 comments on commit 9a9507e

Please sign in to comment.