Fix CSP configuration for django-csp 4 - #4493
Merged
Merged
Conversation
flodolo
approved these changes
Sep 3, 2026
flodolo
left a comment
Collaborator
There was a problem hiding this comment.
Django deal with uppercase variable names… 😵
Collaborator
There was a problem hiding this comment.
One issue pointed out by LLMs: this test would fail locally for someone with SITE=https:// (couldn't verify on the device I'm currently in).
-def test_content_security_policy(rf):
+def test_content_security_policy(rf, settings):
response = CSPMiddleware(lambda request: HttpResponse())(rf.get("/"))
+ # These directives get an http: fallback if the site isn't hosted on HTTPS
+ http = "" if settings.SITE_URL.startswith("https") else " http:"
+
policy = response.headers["Content-Security-Policy"]
assert "default-src 'self'" in policy
assert "connect-src 'self'" in policy
assert "font-src 'self'" in policy
- assert "frame-src https: http:" in policy
+ assert f"frame-src https:{http}" in policy
assert "img-src 'self'" in policy
assert "script-src 'self' 'unsafe-eval'" in policy
assert "style-src 'self' 'unsafe-inline'" in policy
- assert "worker-src https: blob: http:" in policy
+ assert f"worker-src https: blob:{http}" in policy
Collaborator
There was a problem hiding this comment.
CI tests are stripping it out https://github.com/mozilla/pontoon/blob/main/.github/workflows/backend.yml#L73
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #4492.