Skip to content

fix: Backport of #7868 and #7920 #7926

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 4 commits into from
May 24, 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
2 changes: 1 addition & 1 deletion cms/static/cms/js/modules/cms.structureboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ class StructureBoard {

if (CMS.settings.mode === 'structure') {
history.replaceState({}, '', url.toString());
this.ui.html.addClass('cms-overflow');
$('html.cms-structure-mode-structure').addClass('cms-overflow');
}

this.ui.container.css('right', 0);
Expand Down
6 changes: 4 additions & 2 deletions cms/templatetags/cms_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from django.template.loader import render_to_string
from django.urls import reverse
from django.utils.encoding import smart_str
from django.utils.html import escape
from django.utils.html import escape, strip_tags
from django.utils.http import urlencode
from django.utils.translation import get_language, override
from django.utils.translation import gettext_lazy as _
Expand Down Expand Up @@ -405,7 +405,9 @@ def get_value(self, context, name, page_lookup):
if page and name in self.valid_attributes:
func = getattr(page, "get_%s" % name)
ret_val = func(language=lang, fallback=True)
if not isinstance(ret_val, datetime):
if name == 'page_title':
ret_val = strip_tags(ret_val)
elif not isinstance(ret_val, datetime):
ret_val = escape(ret_val)
return ret_val
return ''
Expand Down
26 changes: 19 additions & 7 deletions cms/tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from django.http import HttpResponse
from django.test import RequestFactory
from django.test.utils import override_settings
from django.utils.html import escape
from django.utils.html import strip_tags
from django.utils.timezone import now
from djangocms_text_ckeditor.cms_plugins import TextPlugin
from sekizai.context import SekizaiContext
Expand Down Expand Up @@ -55,20 +55,32 @@ def test_unicode_placeholder_name_fails_fast(self):

def test_page_attribute_tag_escapes_content(self):
script = '<script>alert("XSS");</script>'
ampersand = 'Q&A page'

class FakePage:
def __init__(self, title):
self.title = title
super().__init__()

def get_page_title(self, *args, **kwargs):
return script
return self.title

class FakeRequest:
current_page = FakePage()
GET = {'language': 'en'}

request = FakeRequest()
def __init__(self, page):
self.current_page = page

request_script = FakeRequest(FakePage(script))
request_ampersand = FakeRequest(FakePage(ampersand))
template = '{% load cms_tags %}{% page_attribute page_title %}'
output = self.render_template_obj(template, {}, request)
self.assertNotEqual(script, output)
self.assertEqual(escape(script), output)
output_script = self.render_template_obj(template, {}, request_script)
output_ampersand = self.render_template_obj(template, {}, request_ampersand)

self.assertNotEqual(script, output_script)
self.assertEqual(ampersand, output_ampersand)
self.assertEqual(strip_tags(script), output_script)
self.assertEqual(strip_tags(ampersand), output_ampersand)

def test_json_encoder(self):
self.assertEqual(json_filter(True), 'true')
Expand Down