Repository navigation
Add CSP nonces to the browsable API's script tags for Django 6's built-in CSP #10108
|
Django 6.0 added built-in Content Security Policy support ( Since the inline JavaScript moved to static files (#6069), those scripts load fine under a policy that allows The change I'd propose is the same fix in DRF's two templates. <script src="{% static "rest_framework/js/jquery-3.7.1.min.js" %}"{% if csp_nonce is not None %} nonce="{{ csp_nonce }}"{% endif %}></script>Without the CSP middleware and context processor, For context, NetBox serves DRF's browsable API and is adding CSP support built on Django's for v4.8 (netbox-community/netbox#23502). For now that means overriding the |
Replies: 2 comments
|
The gap is still there on current The browsable API's django-rest-framework/rest_framework/templates/rest_framework/base.html Lines 289 to 302 in 46c40ce django-rest-framework/rest_framework/templates/rest_framework/admin.html Lines 246 to 259 in 46c40ce That is fine under a CSP that allows DRF currently depends on There was earlier CSP work for the browsable API in #8783 / #8784, but it did not put nonces on these script tags. Whether to take this in core is for the maintainers to decide. I am not a maintainer. Until then, overriding the |
|
Hey, yes that sounds like it would be nice to add. For context, there is a pretty big PR porting the browsable API to Bootstrap 5 which I'd like to get into DRF 3.19, which will most likely cause some merge conflict with such a change. |
Hey, yes that sounds like it would be nice to add. For context, there is a pretty big PR porting the browsable API to Bootstrap 5 which I'd like to get into DRF 3.19, which will most likely cause some merge conflict with such a change.