From 36605efd206610fdd64283b5caec3f5662195ada Mon Sep 17 00:00:00 2001 From: Robert George Date: Wed, 1 Feb 2023 12:59:10 -0800 Subject: [PATCH] Added support for secure cookies and django-csp --- bookwyrm/settings.py | 9 +++++++++ bookwyrm/templates/guided_tour/book.html | 2 +- bookwyrm/templates/guided_tour/group.html | 2 +- bookwyrm/templates/guided_tour/home.html | 2 +- bookwyrm/templates/guided_tour/lists.html | 2 +- bookwyrm/templates/guided_tour/search.html | 2 +- bookwyrm/templates/guided_tour/user_books.html | 2 +- bookwyrm/templates/guided_tour/user_groups.html | 2 +- bookwyrm/templates/guided_tour/user_profile.html | 2 +- bookwyrm/templates/layout.html | 2 +- bookwyrm/templates/ostatus/template.html | 4 ++-- .../templates/settings/dashboard/registration_chart.html | 2 +- bookwyrm/templates/settings/dashboard/status_chart.html | 2 +- bookwyrm/templates/settings/dashboard/user_chart.html | 2 +- bookwyrm/templates/settings/dashboard/works_chart.html | 2 +- bookwyrm/views/admin/dashboard.py | 3 +++ requirements.txt | 1 + 17 files changed, 28 insertions(+), 15 deletions(-) diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 61240dbfa..abd71b2dd 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -101,6 +101,7 @@ MIDDLEWARE = [ "django.middleware.locale.LocaleMiddleware", "django.middleware.common.CommonMiddleware", "django.middleware.csrf.CsrfViewMiddleware", + "csp.middleware.CSPMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "bookwyrm.middleware.TimezoneMiddleware", "bookwyrm.middleware.IPBlocklistMiddleware", @@ -335,6 +336,8 @@ PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) PROTOCOL = "http" if USE_HTTPS: PROTOCOL = "https" + SESSION_COOKIE_SECURE = True + CSRF_COOKIE_SECURE = True USE_S3 = env.bool("USE_S3", False) @@ -358,11 +361,17 @@ if USE_S3: MEDIA_FULL_URL = MEDIA_URL STATIC_FULL_URL = STATIC_URL DEFAULT_FILE_STORAGE = "bookwyrm.storage_backends.ImagesStorage" + CSP_DEFAULT_SRC = ("'self'", AWS_S3_CUSTOM_DOMAIN) + CSP_SCRIPT_SRC = ("'self'", AWS_S3_CUSTOM_DOMAIN) else: STATIC_URL = "/static/" MEDIA_URL = "/images/" MEDIA_FULL_URL = f"{PROTOCOL}://{DOMAIN}{MEDIA_URL}" STATIC_FULL_URL = f"{PROTOCOL}://{DOMAIN}{STATIC_URL}" + CSP_DEFAULT_SRC = ("'self'") + CSP_SCRIPT_SRC = ("'self'") + +CSP_INCLUDE_NONCE_IN=['script-src'] OTEL_EXPORTER_OTLP_ENDPOINT = env("OTEL_EXPORTER_OTLP_ENDPOINT", None) OTEL_EXPORTER_OTLP_HEADERS = env("OTEL_EXPORTER_OTLP_HEADERS", None) diff --git a/bookwyrm/templates/guided_tour/book.html b/bookwyrm/templates/guided_tour/book.html index 44a37f65e..a0d60e831 100644 --- a/bookwyrm/templates/guided_tour/book.html +++ b/bookwyrm/templates/guided_tour/book.html @@ -1,6 +1,6 @@ {% load i18n %} - diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index eb904a693..25d2430c0 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -11,7 +11,7 @@ {% block title %}{% endblock %} - diff --git a/bookwyrm/templates/settings/dashboard/registration_chart.html b/bookwyrm/templates/settings/dashboard/registration_chart.html index 3b258fec8..bb51ed8bc 100644 --- a/bookwyrm/templates/settings/dashboard/registration_chart.html +++ b/bookwyrm/templates/settings/dashboard/registration_chart.html @@ -1,5 +1,5 @@ {% load i18n %} -