Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#561 fix: add CSRF_TRUSTED_ORIGINS to fix CSRF admin issue #564

Merged
merged 4 commits into from
Sep 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
# ***********************************************************************
# * CloudHarness Django settings
# ***********************************************************************
from cloudharness.applications import get_current_configuration
from cloudharness import applications, log
from cloudharness.utils.config import CloudharnessConfig as conf

# add the 3rd party apps
INSTALLED_APPS = getattr(
Expand Down Expand Up @@ -33,15 +34,23 @@
# get the application CH config
app_name = settings.PROJECT_NAME.lower()
try:
current_app = get_current_configuration()

current_app = applications.get_current_configuration()
# if secured then set USE_X_FORWARDED_HOST because we are behind the GK proxy
USE_X_FORWARDED_HOST = current_app.harness.secured

# CSRF, set CSRF_TRUSTED_ORIGINS
CH_DOMAIN = conf.get_domain()
CSRF_TRUSTED_ORIGINS = getattr(
settings,
'CSRF_TRUSTED_ORIGINS',
[]) + [f"https://{CH_DOMAIN}", f"https://*.{CH_DOMAIN}"]
except:
# no current app found, fall back to the default settings, there is a god change that
# we are running on a developers local machine
from cloudharness.applications import ApplicationConfiguration
current_app = ApplicationConfiguration({
log.warning("Error setting current app configuration, continuing...")

current_app = applications.ApplicationConfiguration({
"name": app_name,
"harness": {
"database": {
Expand All @@ -51,6 +60,8 @@
}
}
})
# CSRF
CSRF_TRUSTED_ORIGINS = ["http://localhost:8080"]

if current_app.harness.database.type == "sqlite3":
DATABASE_ENGINE = "django.db.backends.sqlite3"
Expand Down