Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔒 [#1944] Set default Referrer-Policy to same-origin #956

Merged
merged 2 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/open_inwoner/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -906,5 +906,4 @@

from .app.csp import * # noqa

SECURE_REFERRER_POLICY = "origin-when-cross-origin"
# SECURE_REFERRER_POLICY = "same-origin"
SECURE_REFERRER_POLICY = "same-origin"
9 changes: 9 additions & 0 deletions src/open_inwoner/pdc/tests/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@

@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls")
class TestPublishedProducts(WebTest):
def test_product_referrer_policy_header(self):
product = ProductFactory()

response = self.client.get(
reverse("products:product_detail", kwargs={"slug": product.slug})
)

self.assertEqual(response.headers["Referrer-Policy"], "same-origin")

def test_only_published_products_exist_on_categories_page_when_anonymous(self):
category = CategoryFactory(path="0001", name="First one", slug="first-one")
product1 = ProductFactory(categories=(category,))
Expand Down
18 changes: 18 additions & 0 deletions src/open_inwoner/pdc/tests/test_product_form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.test import TestCase, override_settings
from django.urls import reverse

from .factories import ProductFactory


@override_settings(ROOT_URLCONF="open_inwoner.cms.tests.urls")
class ProductFormTestCase(TestCase):
def test_product_form_referrer_policy_header(self):
product = ProductFactory(form="foo")

response = self.client.get(
reverse("products:product_form", kwargs={"slug": product.slug})
)

self.assertEqual(
response.headers["Referrer-Policy"], "origin-when-cross-origin"
)
5 changes: 5 additions & 0 deletions src/open_inwoner/pdc/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ class ProductFormView(
breadcrumb_use_pk = False
no_list = True

def dispatch(self, request, *args, **kwargs):
response = super().dispatch(request, *args, **kwargs)
response.headers["Referrer-Policy"] = "origin-when-cross-origin"
return response

def page_title(self):
return f"{self.object.name} {_('Formulier')}"

Expand Down
Loading