Skip to content

Commit 93a0913

Browse files
committed
Support the strictest CSP with nonce for scripts
1 parent f113ab6 commit 93a0913

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

rest_framework/templates/rest_framework/admin.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,19 +244,19 @@ <h4 class="modal-title" id="myModalLabel">{{ error_title }}</h4>
244244
{% endif %}
245245

246246
{% block script %}
247-
<script type="application/json" id="drf_csrf">
247+
<script type="application/json" id="drf_csrf" nonce="{{ request.csp_nonce }}">
248248
{
249249
"csrfHeaderName": "{{ csrf_header_name|default:'X-CSRFToken' }}",
250250
"csrfToken": "{{ csrf_token }}"
251251
}
252252
</script>
253-
<script src="{% static "rest_framework/js/jquery-3.7.1.min.js" %}"></script>
254-
<script src="{% static "rest_framework/js/ajax-form.js" %}"></script>
255-
<script src="{% static "rest_framework/js/csrf.js" %}"></script>
256-
<script src="{% static "rest_framework/js/bootstrap.min.js" %}"></script>
257-
<script src="{% static "rest_framework/js/prettify-min.js" %}"></script>
258-
<script src="{% static "rest_framework/js/default.js" %}"></script>
259-
<script src="{% static "rest_framework/js/load-ajax-form.js" %}"></script>
253+
<script src="{% static "rest_framework/js/jquery-3.7.1.min.js" %}" nonce="{{ request.csp_nonce }}"></script>
254+
<script src="{% static "rest_framework/js/ajax-form.js" %}" nonce="{{ request.csp_nonce }}"></script>
255+
<script src="{% static "rest_framework/js/csrf.js" %}" nonce="{{ request.csp_nonce }}"></script>
256+
<script src="{% static "rest_framework/js/bootstrap.min.js" %}" nonce="{{ request.csp_nonce }}"></script>
257+
<script src="{% static "rest_framework/js/prettify-min.js" %}" nonce="{{ request.csp_nonce }}"></script>
258+
<script src="{% static "rest_framework/js/default.js" %}" nonce="{{ request.csp_nonce }}"></script>
259+
<script src="{% static "rest_framework/js/load-ajax-form.js" %}" nonce="{{ request.csp_nonce }}"></script>
260260
{% endblock %}
261261
</body>
262262
{% endblock %}

rest_framework/templates/rest_framework/base.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,19 +287,19 @@ <h1>{{ name }}</h1>
287287
{% endif %}
288288

289289
{% block script %}
290-
<script type="application/json" id="drf_csrf">
290+
<script type="application/json" id="drf_csrf" nonce="{{ request.csp_nonce }}">
291291
{
292292
"csrfHeaderName": "{{ csrf_header_name|default:'X-CSRFToken' }}",
293293
"csrfToken": "{% if request %}{{ csrf_token }}{% endif %}"
294294
}
295295
</script>
296-
<script src="{% static "rest_framework/js/jquery-3.7.1.min.js" %}"></script>
297-
<script src="{% static "rest_framework/js/ajax-form.js" %}"></script>
298-
<script src="{% static "rest_framework/js/csrf.js" %}"></script>
299-
<script src="{% static "rest_framework/js/bootstrap.min.js" %}"></script>
300-
<script src="{% static "rest_framework/js/prettify-min.js" %}"></script>
301-
<script src="{% static "rest_framework/js/default.js" %}"></script>
302-
<script src="{% static "rest_framework/js/load-ajax-form.js" %}"></script>
296+
<script src="{% static "rest_framework/js/jquery-3.7.1.min.js" %}" nonce="{{ request.csp_nonce }}"></script>
297+
<script src="{% static "rest_framework/js/ajax-form.js" %}" nonce="{{ request.csp_nonce }}"></script>
298+
<script src="{% static "rest_framework/js/csrf.js" %}" nonce="{{ request.csp_nonce }}"></script>
299+
<script src="{% static "rest_framework/js/bootstrap.min.js" %}" nonce="{{ request.csp_nonce }}"></script>
300+
<script src="{% static "rest_framework/js/prettify-min.js" %}" nonce="{{ request.csp_nonce }}"></script>
301+
<script src="{% static "rest_framework/js/default.js" %}" nonce="{{ request.csp_nonce }}"></script>
302+
<script src="{% static "rest_framework/js/load-ajax-form.js" %}" nonce="{{ request.csp_nonce }}"></script>
303303
{% endblock %}
304304

305305
</body>

rest_framework/templates/rest_framework/docs/error.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ <h2>Overriding this template</h2>
6666

6767

6868

69-
<script src="{% static 'rest_framework/js/jquery-3.7.1.min.js' %}"></script>
69+
<script src="{% static 'rest_framework/js/jquery-3.7.1.min.js' %}" nonce="{{ request.csp_nonce }}"></script>
7070
</body>
7171
</html>

rest_framework/templates/rest_framework/docs/index.html

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
<link href="{% static 'rest_framework/docs/img/favicon.ico' %}" rel="shortcut icon">
1818

1919
{% if code_style %}<style>{{ code_style }}</style>{% endif %}
20-
<script src="{% static 'rest_framework/js/coreapi-0.1.1.js' %}"></script>
21-
<script src="{% url 'api-docs:schema-js' %}"></script>
20+
<script src="{% static 'rest_framework/js/coreapi-0.1.1.js' %}" nonce="{{ request.csp_nonce }}"></script>
21+
<script src="{% url 'api-docs:schema-js' %}" nonce="{{ request.csp_nonce }}"></script>
2222

2323
</head>
2424

@@ -38,11 +38,11 @@
3838
{% include "rest_framework/docs/auth/basic.html" %}
3939
{% include "rest_framework/docs/auth/session.html" %}
4040

41-
<script src="{% static 'rest_framework/js/jquery-3.7.1.min.js' %}"></script>
42-
<script src="{% static 'rest_framework/js/bootstrap.min.js' %}"></script>
43-
<script src="{% static 'rest_framework/docs/js/jquery.json-view.min.js' %}"></script>
44-
<script src="{% static 'rest_framework/docs/js/api.js' %}"></script>
45-
<script>
41+
<script src="{% static 'rest_framework/js/jquery-3.7.1.min.js' %}" nonce="{{ request.csp_nonce }}"></script>
42+
<script src="{% static 'rest_framework/js/bootstrap.min.js' %}" nonce="{{ request.csp_nonce }}"></script>
43+
<script src="{% static 'rest_framework/docs/js/jquery.json-view.min.js' %}" nonce="{{ request.csp_nonce }}"></script>
44+
<script src="{% static 'rest_framework/docs/js/api.js' %}" nonce="{{ request.csp_nonce }}"></script>
45+
<script nonce="{{ request.csp_nonce }}">
4646
{% if user.is_authenticated %}
4747
window.auth = {
4848
'type': 'session',
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{% load rest_framework %}
22
{% load static %}
33
<pre class="highlight javascript hide" data-language="javascript"><code>{% code html %}<!-- Load the JavaScript client library -->
4-
<script src="{% static 'rest_framework/js/coreapi-0.1.1.js' %}"></script>
5-
<script src="{% url 'api-docs:schema-js' %}"></script>{% endcode %}</code></pre>
4+
<script src="{% static 'rest_framework/js/coreapi-0.1.1.js' %}" nonce="{{ request.csp_nonce }}"></script>
5+
<script src="{% url 'api-docs:schema-js' %}" nonce="{{ request.csp_nonce }}"></script>{% endcode %}</code></pre>

0 commit comments

Comments
 (0)