From d6591bce240c1ac09a68541c535e7945d845f315 Mon Sep 17 00:00:00 2001 From: Rob Hudson Date: Thu, 12 Sep 2024 08:12:24 -0700 Subject: [PATCH] Prepare for 4.0b2 release --- .pre-commit-config.yaml | 12 ++++++++++-- CHANGES.md | 9 +++++++++ docs/decorators.rst | 2 +- docs/migration-guide.rst | 14 ++++++++++---- pyproject.toml | 2 +- 5 files changed, 31 insertions(+), 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c70afbe..d695066 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,7 +14,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.0 + rev: v0.6.4 hooks: # Run the linter - id: ruff @@ -22,6 +22,14 @@ repos: # Run the formatter - id: ruff-format - repo: https://github.com/tox-dev/pyproject-fmt - rev: 2.1.3 + rev: 2.2.3 hooks: - id: pyproject-fmt + - repo: https://github.com/adamchainz/blacken-docs + rev: 1.18.0 + hooks: + - id: blacken-docs + additional_dependencies: + - black==24.4.2 + files: 'docs/.*\.rst$' + args: ["--rst-literal-block"] diff --git a/CHANGES.md b/CHANGES.md index 77747e3..8eec4b9 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,8 +3,17 @@ CHANGES Unreleased ========== + +4.0b2 +===== - Add type hints. ([#228](https://github.com/mozilla/django-csp/pull/228)) - Expand ruff configuration and move into pyproject.toml [[#234](https://github.com/mozilla/django-csp/pull/234)] +- Documentation fixes by jamesbeith and jcari-dev +- Simplify middleware logic ([#226](https://github.com/mozilla/django-csp/pull/226)) +- Report percentage of 100% should always send CSP report ([#236](https://github.com/mozilla/django-csp/pull/236)) +- Changes to make `CSPMiddleware` easier to subclass ([#237](https://github.com/mozilla/django-csp/pull/237)) +- Change `REPORT_PERCENTAGE` to allow floats (e.g. for values < 1%) ([#242](https://github.com/mozilla/django-csp/pull/242)) +- Add Django 5.1 support ([#243](https://github.com/mozilla/django-csp/pull/243)) 4.0b1 ===== diff --git a/docs/decorators.rst b/docs/decorators.rst index 981da3d..878f927 100644 --- a/docs/decorators.rst +++ b/docs/decorators.rst @@ -53,7 +53,7 @@ settings. If there is no setting, the value passed to the decorator will be used .. note:: To quote the CSP spec: "There's no inheritance; ... the default list is not used for that - resource type" if it is set. E.g., the following will not allow images from 'self':: + resource type" if it is set. E.g., the following will not allow images from 'self': default-src 'self'; img-src imgsrv.com diff --git a/docs/migration-guide.rst b/docs/migration-guide.rst index b5b2f27..64b43d4 100644 --- a/docs/migration-guide.rst +++ b/docs/migration-guide.rst @@ -213,6 +213,7 @@ An existing custom middleware, such as this: from csp.middleware import CSPMiddleware, PolicyParts + class ACustomMiddleware(CSPMiddleware): def build_policy(self, request: HttpRequest, response: HttpResponseBase) -> str: @@ -231,7 +232,7 @@ An existing custom middleware, such as this: replace = getattr(response, "_csp_replace_ro", {}) nonce = getattr(request, "_csp_nonce", None) - # ... do custom CSP report only policy logic ... + # ... do custom CSP report-only policy logic ... return build_policy(config=config, update=update, replace=replace, nonce=nonce) @@ -246,13 +247,18 @@ can be replaced with this: class ACustomMiddleware(CSPMiddleware): - def get_policy_parts(self, request: HttpRequest, response: HttpResponseBase, report_only: bool = False) -> PolicyParts: + def get_policy_parts( + self, + request: HttpRequest, + response: HttpResponseBase, + report_only: bool = False, + ) -> PolicyParts: policy_parts = super().get_policy_parts(request, response, report_only) if report_only: - # ... do custom CSP report only policy logic ... + ... # do custom CSP report-only policy logic else: - # ... do custom CSP policy logic ... + ... # do custom CSP policy logic return policy_parts diff --git a/pyproject.toml b/pyproject.toml index f710fbb..16d1c1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ requires = [ [project] name = "django-csp" -version = "4.0b1" +version = "4.0b2" description = "Django Content Security Policy support." readme = "README.rst" license = { text = "BSD" }