Skip to content

Commit 241d1cb

Browse files
fsbraunGithub Release Action
andauthored
fix: XSS vulnerability for page title (#8075)
* Fix: XSS vulnerability for page title * fix linting --------- Co-authored-by: Github Release Action <info@django-cms.org>
1 parent 0224f1e commit 241d1cb

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

cms/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def create_page(title, template, language, menu_title=None, slug=None,
136136
xframe_options=constants.X_FRAME_OPTIONS_INHERIT):
137137
"""
138138
Creates a :class:`cms.models.Page` instance and returns it. Also
139-
creates a :class:`cms.models.Title` instance for the specified
139+
creates a :class:`cms.models.PageContent` instance for the specified
140140
language.
141141
142142
.. warning::

cms/templatetags/cms_tags.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,7 @@ def get_value(self, context, name, page_lookup):
441441
if page and name in self.valid_attributes:
442442
func = getattr(page, "get_%s" % name)
443443
ret_val = func(language=lang, fallback=True)
444-
if name == 'page_title':
445-
ret_val = strip_tags(ret_val)
446-
elif not isinstance(ret_val, datetime):
444+
if not isinstance(ret_val, datetime):
447445
ret_val = escape(ret_val)
448446
return ret_val
449447
return ''

cms/tests/test_templatetags.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
from django.test import RequestFactory
1212
from django.test.utils import override_settings
1313
from django.utils.encoding import force_str
14-
from django.utils.html import strip_tags
14+
from django.utils.html import escape
1515
from django.utils.timezone import now
1616
from django.utils.translation import override as force_language
1717
from djangocms_text_ckeditor.cms_plugins import TextPlugin
18-
from djangocms_text_ckeditor.models import Text
1918
from sekizai.context import SekizaiContext
2019

2120
import cms
@@ -139,6 +138,7 @@ def test_unicode_placeholder_name_fails_fast(self):
139138
def test_page_attribute_tag_escapes_content(self):
140139
script = '<script>alert("XSS");</script>'
141140
ampersand = 'Q&A page'
141+
partial = '"><img src=x onerror=alert(1) "'
142142

143143
class FakePage:
144144
def __init__(self, title):
@@ -159,11 +159,14 @@ def __init__(self, page):
159159
template = '{% load cms_tags %}{% page_attribute page_title %}'
160160
output_script = self.render_template_obj(template, {}, request_script)
161161
output_ampersand = self.render_template_obj(template, {}, request_ampersand)
162+
output_partial = self.render_template_obj(template, {}, FakeRequest(FakePage(partial)))
162163

163164
self.assertNotEqual(script, output_script)
164-
self.assertEqual(ampersand, output_ampersand)
165-
self.assertEqual(strip_tags(script), output_script)
166-
self.assertEqual(strip_tags(ampersand), output_ampersand)
165+
self.assertNotEqual(ampersand, output_ampersand)
166+
self.assertNotEqual(partial, output_partial)
167+
self.assertEqual(escape(script), output_script)
168+
self.assertEqual(escape(ampersand), output_ampersand)
169+
self.assertEqual(escape(partial), output_partial)
167170

168171
def test_json_encoder(self):
169172
self.assertEqual(json_filter(True), 'true')

0 commit comments

Comments
 (0)