8000 Fixed #6346 -- Set xframe options exempt on cached response by czpython · Pull Request #6404 · django-cms/django-cms · GitHub
[go: up one dir, main page]

Skip to content

Fixed #6346 -- Set xframe options exempt on cached response #6404

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

Merged
merged 1 commit into from
Jun 5, 2018
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ Contributors (based on gitlog, 503 unique authors):
* martinkosir
* Matas Dailyda
* Mateusz Dereniowski
* Mateusz Kamycki
* Mateusz Marzantowicz
* mathijs
* Matt Chisholm
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
=== 3.4.7 (unreleased) ===

* Removed extra quotation mark from the sideframe button template
* Fixed a bug where xframe options were processed by clickjacking middleware
when page was served from cache, rather then get this value from cache


=== 3.4.6 (2018-03-26) ===
Expand Down
34 changes: 34 additions & 0 deletions cms/tests/test_page.py
DB4D
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,40 @@ def test_top_level_page_inherited_xframe_options_are_applied(self):
resp = self.client.get(page.get_absolute_url('en'))
self.assertEqual(resp.get('X-Frame-Options'), 'SAMEORIGIN')

def test_xframe_options_with_cms_page_cache_and_clickjacking_middleware(self):
# Refs: 6346
if getattr(settings, 'MIDDLEWARE', None):
override = {
'MIDDLEWARE': settings.MIDDLEWARE + [
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
}
else:
override = {
'MIDDLEWARE_CLASSES': settings.MIDDLEWARE_CLASSES + [
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
}

override['CMS_PAGE_CACHE'] = True

with self.settings(**override):
page = create_page(
'test page 1',
'nav_playground.html',
'en',
published=True,
xframe_options=Page.X_FRAME_OPTIONS_ALLOW,
)

# Normal response from render_page
resp = self.client.get(page.get_absolute_url('en'))
self.assertEqual(resp.get('X-Frame-Options'), None)

# Response from page cache
resp = self.client.get(page.get_absolute_url('en'))
self.assertEqual(resp.get('X-Frame-Options'), None)


class PreviousFilteredSiblingsTests(CMSTestCase):

Expand Down
1 change: 1 addition & 0 deletions cms/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def details(request, slug):
if cache_content is not None:
content, headers, expires_datetime = cache_content
response = HttpResponse(content)
response.xframe_options_exempt = True
response._headers = headers
# Recalculate the max-age header for this cached response
max_age = int(
Expand Down
0