Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Allow to set SECURE_PROXY_SSL_HEADER in the config

Roland Geider03c2a7f0f749
diff --git a/extras/docker/development/settings.py b/extras/docker/development/settings.py
index 3624cabde..2bc12a5d6 100644
--- a/extras/docker/development/settings.py
+++ b/extras/docker/development/settings.py
@@ -7,7 +7,6 @@ from wger.settings_global import *
# Third Party
import environ
-
env = environ.Env(
# set casting, default value
DJANGO_DEBUG=(bool, False)
@@ -46,7 +45,6 @@ TIME_ZONE = env.str("TIME_ZONE", 'Europe/Berlin')
# Make this unique, and don't share it with anybody.
SECRET_KEY = env.str("SECRET_KEY", 'wger-docker-supersecret-key-1234567890!@#$%^&*(-_)')
-
# Your reCaptcha keys
RECAPTCHA_PUBLIC_KEY = env.str('RECAPTCHA_PUBLIC_KEY', '')
RECAPTCHA_PRIVATE_KEY = env.str('RECAPTCHA_PRIVATE_KEY', '')
@@ -85,7 +83,6 @@ if os.environ.get("ENABLE_EMAIL"):
EMAIL_USE_SSL = env.bool("EMAIL_USE_SSL", True)
EMAIL_TIMEOUT = 60
-
# Sender address used for sent emails
WGER_SETTINGS['EMAIL_FROM'] = f'wger Workout Manager <{env.str("FROM_EMAIL")}>'
DEFAULT_FROM_EMAIL = WGER_SETTINGS['EMAIL_FROM']
@@ -94,10 +91,9 @@ DEFAULT_FROM_EMAIL = WGER_SETTINGS['EMAIL_FROM']
WGER_SETTINGS["ALLOW_REGISTRATION"] = env.bool("ALLOW_REGISTRATION", True)
WGER_SETTINGS["ALLOW_GUEST_USERS"] = env.bool("ALLOW_GUEST_USERS", True)
WGER_SETTINGS["ALLOW_UPLOAD_VIDEOS"] = env.bool("ALLOW_UPLOAD_VIDEOS", True)
-WGER_SETTINGS["MIN_ACCOUNT_AGE_TO_TRUST"] = env.int("MIN_ACCOUNT_AGE_TO_TRUST", 21) # in days
+WGER_SETTINGS["MIN_ACCOUNT_AGE_TO_TRUST"] = env.int("MIN_ACCOUNT_AGE_TO_TRUST", 21) # in days
WGER_SETTINGS["EXERCISE_CACHE_TTL"] = env.int("EXERCISE_CACHE_TTL", 3600)
-
# Cache
if os.environ.get("DJANGO_CACHE_BACKEND"):
CACHES = {
@@ -117,7 +113,6 @@ COMPRESS_ROOT = STATIC_ROOT
# The site's domain as used by the email verification workflow
EMAIL_PAGE_DOMAIN = 'http://localhost/'
-
#
# Django Axes
#
@@ -138,5 +133,11 @@ SIMPLE_JWT['SIGNING_KEY'] = env.str("SIGNING_KEY", SECRET_KEY)
#
CSRF_TRUSTED_ORIGINS = env.list(
"CSRF_TRUSTED_ORIGINS",
- default=['http://127.0.0.1', 'http://localhost'],
+ default=['http://127.0.0.1', 'http://localhost', 'https://localhost'],
)
+
+if env.bool('X_FORWARDED_PROTO_HEADER_SET', False):
+ SECURE_PROXY_SSL_HEADER = (
+ env.str('SECURE_PROXY_SSL_HEADER', 'HTTP_X_FORWARDED_PROTO'),
+ 'https'
+ )
diff --git a/wger/settings.tpl b/wger/settings.tpl
index 682f1d627..676d1768d 100644
--- a/wger/settings.tpl
+++ b/wger/settings.tpl
@@ -4,7 +4,6 @@
# wger
from wger.settings_global import *
-
# Use 'DEBUG = True' to get more details for server errors
DEBUG = True
@@ -27,9 +26,8 @@ DATABASES = {{
}}
}} # yapf: disable
-
# List of administrations
-ADMINS = (('Your name', '[email protected]'), )
+ADMINS = (('Your name', '[email protected]'),)
MANAGERS = ADMINS
# SERVER_EMAIL = '[email protected]'
@@ -63,7 +61,7 @@ ALLOWED_HOSTS = [
]
# This might be a good idea if you set up redis
-#SESSION_ENGINE = "django.contrib.sessions.backends.cache"
+# SESSION_ENGINE = "django.contrib.sessions.backends.cache"
# Configure a real backend in production
# See: https://docs.djangoproject.com/en/dev/topics/email/#email-backends
@@ -84,7 +82,12 @@ AXES_ENABLED = False
# AXES_HANDLER = 'axes.handlers.cache.AxesCacheHandler'
#
-# Sometimes needed if deployed behind a proxy, etc.
+# Sometimes needed if deployed behind a proxy with HTTPS enabled:
# https://docs.djangoproject.com/en/4.1/ref/csrf/
#
# CSRF_TRUSTED_ORIGINS = ['http://127.0.0.1', 'https://my.domain.example.com']
+
+# Alternative to above, needs changes to the reverse proxy's config
+# https://docs.djangoproject.com/en/4.1/ref/settings/#secure-proxy-ssl-header
+#
+# SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO, 'https')