Skip to content

Fix CSP in admin to allow django's jsi18n admin view as a script#24422

Open
diox wants to merge 4 commits intomozilla:masterfrom
diox:fix-csp-admin
Open

Fix CSP in admin to allow django's jsi18n admin view as a script#24422
diox wants to merge 4 commits intomozilla:masterfrom
diox:fix-csp-admin

Conversation

@diox
Copy link
Member

@diox diox commented Feb 5, 2026

Fixes mozilla/addons#15832

Testing

  • This should fix built-in datetime widgets in the admin. Without this change, everywhere you can modify a datetime that we haven't customized, you would have to enter the date & time manually. Now you get a fancy widget. The change waffle switch page has those for created&modified dates for instance
  • This should fix the number of items selected not updating at the top of the list (0 of 100 selected), for changelist pages that display checkboxes, such as the user profiles admin changelist.

@diox diox marked this pull request as ready for review February 6, 2026 11:10
@diox diox requested a review from eviljeff February 6, 2026 11:10
@eviljeff
Copy link
Member

eviljeff commented Feb 6, 2026

I can't get this to work on the waffle switch change page - the date widgets are still manual text, and http://olympia.test/en-GB/admin/models/jsi18n/ (in my case) is still blocked due to CSP.

the csp header in the html was:

frame-src https://www.recaptcha.net/recaptcha/; script-src https://.google-analytics.com https://.googletagmanager.com https://www.recaptcha.net/recaptcha/ https://www.gstatic.com/recaptcha/ https://www.gstatic.cn/recaptcha/ https://addons.mozilla.org/static-server/ http://olympia.test/static-server/ http://www.google-analytics.com; img-src 'self' blob: data: https://addons.mozilla.org/static-server/ https://addons.mozilla.org/user-media/ https://.google-analytics.com https://.googletagmanager.com http://olympia.test/user-media/ http://olympia.test/static-server/ http://www.google-analytics.com; style-src 'unsafe-inline' https://addons.mozilla.org/static-server/ http://olympia.test/static-server/; child-src https://www.recaptcha.net/recaptcha/; connect-src 'self' https://.google-analytics.com https://.analytics.google.com https://*.googletagmanager.com http://olympia.test; media-src https://videos.cdn.mozilla.net; object-src 'none'; form-action 'self'; font-src 'self' https://addons.mozilla.org/static-server/ http://olympia.test/static-server/; default-src 'none'; report-uri /csp-report

Copy link
Member

@eviljeff eviljeff left a comment

Choose a reason for hiding this comment

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

can haz l10n, por favor

if request.path.startswith('/en-US/admin/models/'):
policy_parts.update = {
'script-src': (
f'{settings.INTERNAL_SITE_URL}/en-US/admin/models/jsi18n/'
Copy link
Member

@eviljeff eviljeff Feb 6, 2026

Choose a reason for hiding this comment

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

Ah, this is it. It's hard-coded to en-US.

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.

[Bug]: Django built-in widgets don't load in the admin

2 participants