Skip to content

Commit 3179613

Browse files
authored
Drop unnecessary CSP directives for gold view (readthedocs#11605)
* Drop unnecessary CSP directives for gold view This does not seem needed, as there is no inline script src in `subscription_detail.html`. It seems like maybe we wrote this for `subscription_form.html`, which was old. This conditional was breaking the view for me locally, as we don't have any CSP directives for `script-src` locally, we only have these in production. Because of this, there are no other `script-src` exceptions. * Revert test functionality
1 parent c5004d3 commit 3179613

File tree

2 files changed

+12
-22
lines changed

2 files changed

+12
-22
lines changed

readthedocs/gold/tests/test_views.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import re
22

33
from django.contrib.auth.models import User
4-
from django.test import TestCase, override_settings
4+
from django.test import TestCase
55
from django.urls import reverse
66
from django_dynamic_fixture import get
77

@@ -11,17 +11,19 @@ def setUp(self):
1111
self.user = get(User)
1212

1313
def test_csp_headers(self):
14+
"""
15+
Test CSP headers aren't altered.
16+
17+
This view originally altered the CSP directives based on whether we were
18+
using the new dashboard. We weren't using inline scripts in this view
19+
however, so this was reverted. The tests remain for now, but aren't
20+
super useful and will break when we change `script-src` in base settings.
21+
"""
1422
self.client.force_login(self.user)
1523
csp_header = "Content-Security-Policy"
1624
script_src_regex = re.compile(r".*\s+script-src [^;]*'unsafe-inline'")
1725
url = reverse("gold_detail")
1826

19-
with override_settings(RTD_EXT_THEME_ENABLED=False):
20-
resp = self.client.get(url)
21-
self.assertEqual(resp.status_code, 200)
22-
self.assertIsNone(script_src_regex.match(resp[csp_header]))
23-
24-
with override_settings(RTD_EXT_THEME_ENABLED=True):
25-
resp = self.client.get(url)
26-
self.assertEqual(resp.status_code, 200)
27-
self.assertTrue(script_src_regex.match(resp[csp_header]))
27+
resp = self.client.get(url)
28+
self.assertEqual(resp.status_code, 200)
29+
self.assertIsNone(script_src_regex.match(resp[csp_header]))

readthedocs/gold/views.py

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,6 @@ class GoldSubscription(
3939
form_class = GoldSubscriptionForm
4040
template_name = "gold/subscription_detail.html"
4141

42-
def dispatch(self, request, *args, **kwargs):
43-
response = super().dispatch(request, *args, **kwargs)
44-
# Allow inline scripts for the gold view.
45-
# We are using inline javascript to initialize Stripe Checkout.
46-
# Allowing inline scripts defeats the purpose of using CSP,
47-
# but we are limiting it to this view.
48-
# TODO: use the `@csp_update` decorator once we are running
49-
# ext-theme by default.
50-
if settings.RTD_EXT_THEME_ENABLED:
51-
response._csp_update = {"script-src": "'unsafe-inline'"}
52-
return response
53-
5442
def get(self, *args, **kwargs):
5543
subscribed = self.request.GET.get("subscribed", None)
5644
if subscribed == "true":

0 commit comments

Comments
 (0)