From a5dc0195ba54bd8b28b3acb94a7731f7bf051728 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Sun, 11 Oct 2026 21:08:47 +0200 Subject: [PATCH] Switch to Django's builtin CSP django-csp is still updated to newer django versions however having it built in means we no longer have to depend an external dependency. --- pyproject.toml | 1 - settings.py | 22 ++++++++++------------ templates/devel/clock.html | 2 +- templates/devel/index.html | 2 +- templates/devel/packages.html | 2 +- templates/devel/tier0_mirror.html | 2 +- templates/mirrors/mirror_details.html | 2 +- templates/mirrors/mirrors.html | 2 +- templates/mirrors/status.html | 2 +- templates/mirrors/url_details.html | 2 +- templates/news/add.html | 2 +- templates/packages/details.html | 2 +- templates/packages/differences.html | 2 +- templates/packages/groups.html | 2 +- templates/packages/packages_list.html | 2 +- templates/packages/signoffs.html | 2 +- templates/packages/stale_relations.html | 2 +- templates/public/keys.html | 2 +- templates/releng/release_list.html | 2 +- templates/todolists/list.html | 2 +- templates/todolists/view.html | 2 +- templates/visualize/index.html | 2 +- uv.lock | 15 --------------- 23 files changed, 30 insertions(+), 48 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 52057fc6f..dce253b3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,6 @@ dependencies = [ "bleach==6.4.0", "django==6.0.9", "django-countries==9.1.0", - "django-csp==4.0", "django-prometheus==2.5.0", "feedparser==6.0.14", "ipy==1.1", diff --git a/settings.py b/settings.py index 914420ce3..9dee71f25 100644 --- a/settings.py +++ b/settings.py @@ -2,7 +2,7 @@ import sys from os import path -from csp.constants import NONCE, SELF +from django.utils.csp import CSP # Set the debug values DEBUG = False @@ -56,7 +56,7 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.middleware.http.ConditionalGetMiddleware', - 'csp.middleware.CSPMiddleware', + 'django.middleware.csp.ContentSecurityPolicyMiddleware', ] # Base of the URL hierarchy @@ -97,15 +97,13 @@ SECURE_CONTENT_TYPE_NOSNIFF = True # CSP Settings -CONTENT_SECURITY_POLICY = { - "DIRECTIVES": { - "default-src": [SELF], - "script-src": [SELF, NONCE], - "img-src": [SELF, "data:"], - "base-uri": ["'none'"], - "form-action": [SELF], - "frame-ancestors": ["'none'"], - } +SECURE_CSP = { + "default-src": [CSP.SELF], + "script-src": [CSP.SELF, CSP.NONCE], + "img-src": [CSP.SELF, "data:"], + "base-uri": [CSP.NONE], + "form-action": [CSP.SELF], + "frame-ancestors": [CSP.NONE], } # Use new test runner @@ -252,7 +250,7 @@ 'django.template.context_processors.request', 'django.template.context_processors.debug', 'django.contrib.messages.context_processors.messages', - 'csp.context_processors.nonce', + 'django.template.context_processors.csp', 'main.context_processors.mastodon_link', ], "loaders": [ diff --git a/templates/devel/clock.html b/templates/devel/clock.html index 79d315011..eaa538703 100644 --- a/templates/devel/clock.html +++ b/templates/devel/clock.html @@ -61,7 +61,7 @@

Developer World Clocks

{% block script_block %} {% load cdn %}{% jquery %}{% jquery_tablesorter %} - - - - - - - - - - - - - - - - -