Skip to content

Commit fdf4e93

Browse files
committed
Enable security settings only when in production environment
Depends on new environment variable `PROD_ENV` being set to true
1 parent ec3ab2b commit fdf4e93

1 file changed

Lines changed: 27 additions & 24 deletions

File tree

app/epa/settings.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343

4444
# SECURITY WARNING: don't run with debug turned on in production!
4545
DEBUG = env.bool("DEBUG", default=False)
46+
PROD_ENV = env.bool("PROD_ENV", default=False)
47+
4648
if DEBUG is True:
4749
STATICFILES_FINDERS.append("sass_processor.finders.CssFinder")
4850
SASS_PROCESSOR_ROOT = STATIC_ROOT
@@ -262,27 +264,28 @@
262264
"orm": "default",
263265
}
264266

265-
# SECURITY
266-
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect
267-
SECURE_SSL_REDIRECT = env.bool("DJANGO_SECURE_SSL_REDIRECT", default=True)
268-
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure
269-
SESSION_COOKIE_SECURE = True
270-
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-name
271-
SESSION_COOKIE_NAME = "__Secure-sessionid"
272-
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure
273-
CSRF_COOKIE_SECURE = True
274-
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-seconds
275-
# TODO: set this to 60 seconds first and then to 518400 once you prove the former works
276-
SECURE_HSTS_SECONDS = 60
277-
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-include-subdomains
278-
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool(
279-
"DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS",
280-
default=True,
281-
)
282-
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload
283-
SECURE_HSTS_PRELOAD = env.bool("DJANGO_SECURE_HSTS_PRELOAD", default=True)
284-
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
285-
SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
286-
"DJANGO_SECURE_CONTENT_TYPE_NOSNIFF",
287-
default=True,
288-
)
267+
if PROD_ENV:
268+
# SECURITY
269+
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-ssl-redirect
270+
SECURE_SSL_REDIRECT = env.bool("DJANGO_SECURE_SSL_REDIRECT", default=True)
271+
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-secure
272+
SESSION_COOKIE_SECURE = True
273+
# https://docs.djangoproject.com/en/dev/ref/settings/#session-cookie-name
274+
SESSION_COOKIE_NAME = "__Secure-sessionid"
275+
# https://docs.djangoproject.com/en/dev/ref/settings/#csrf-cookie-secure
276+
CSRF_COOKIE_SECURE = True
277+
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-seconds
278+
# TODO: set this to 60 seconds first and then to 518400 once you prove the former works
279+
SECURE_HSTS_SECONDS = 60
280+
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-include-subdomains
281+
SECURE_HSTS_INCLUDE_SUBDOMAINS = env.bool(
282+
"DJANGO_SECURE_HSTS_INCLUDE_SUBDOMAINS",
283+
default=True,
284+
)
285+
# https://docs.djangoproject.com/en/dev/ref/settings/#secure-hsts-preload
286+
SECURE_HSTS_PRELOAD = env.bool("DJANGO_SECURE_HSTS_PRELOAD", default=True)
287+
# https://docs.djangoproject.com/en/dev/ref/middleware/#x-content-type-options-nosniff
288+
SECURE_CONTENT_TYPE_NOSNIFF = env.bool(
289+
"DJANGO_SECURE_CONTENT_TYPE_NOSNIFF",
290+
default=True,
291+
)

0 commit comments

Comments
 (0)