Skip to content

Conversation

@Chiemezuo
Copy link
Contributor

Introduction

From Django 6.0 which should be released in December 2025, Django will have an in-built CSP package, and will no longer need the external django-csp package.

This PR, although small, has some months to go before being ready for a merge, but it's good to have this under our radar.

Copy link
Member

@thibaudcolas thibaudcolas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! This seems pretty mergeable to me if those changes are limited to the one settings and requirements files. I think it’d make sense to merge this as soon as Django 6.0 alpha 1 is released, possibly even before, so we can try this out on the main branch of bakerydemo. Just making sure any loading of Django 6.0 APIs are behind a Django version check.

Also we would need to remove the dependency on django-csp.

@@ -1,4 +1,4 @@
Django>=5.2,<5.3
Django>=6.0,<7.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Django>=6.0,<7.0
Django>=5.2,<6.0

I believe this will allow us to have working installs for most users, and for early adopters support installing release candidates of Django 6.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the <6.0, wouldn't that mean that it would not be possible to install a release candidate for 6.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we could remove the dependency on django-csp when 6.0 is available. For now, I suppose we could leave it, though.

SECURE_CSP_REPORT_ONLY = {
"default-src": [CSP.SELF, "*.wagtail.org"],
# Add more directives as needed.
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you update this so we can preserve how this is done with environment variables? I think ideally we would want to preserve our ability to configure this with environment variables, just do this with the vanilla Django implementation.

I think this should also be done only when if "CSP_DEFAULT_SRC" in os.environ:.

import os

import dj_database_url
from django.utils.csp import CSP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible for us to move this and the middleware addition within a Django version check, so we can merge this while still supporting Django 5.2?

Comment on lines 231 to 232
# Gravatar images should be disabled for strict CSP
WAGTAIL_GRAVATAR_PROVIDER_URL = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would want to keep using Gravatar, it’s just a matter of configuration no? We can allow loading images from there while still having a strict CSP.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we can do this. But we would be trusting all the content from Gravatar to not be malicious. What do you think?

@Chiemezuo Chiemezuo requested a review from thibaudcolas August 27, 2025 06:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants