diff --git a/cms/djangoapps/contentstore/tests/test_contentstore.py b/cms/djangoapps/contentstore/tests/test_contentstore.py index a978d3617b..5e1aabb791 100644 --- a/cms/djangoapps/contentstore/tests/test_contentstore.py +++ b/cms/djangoapps/contentstore/tests/test_contentstore.py @@ -681,6 +681,16 @@ class MiscCourseTests(ContentStoreTestCase): for expected in expected_types: self.assertIn(expected, resp.content) + @ddt.data("", "alert('hi')", "") + def test_container_handler_xss_prevent(self, malicious_code): + """ + Test that XSS attack is prevented + """ + resp = self.client.get_html(get_url('container_handler', self.vert_loc) + '?action=' + malicious_code) + self.assertEqual(resp.status_code, 200) + # Test that malicious code does not appear in html + self.assertNotIn(malicious_code, resp.content) + @patch('django.conf.settings.DEPRECATED_ADVANCED_COMPONENT_TYPES', []) def test_advanced_components_in_edit_unit(self): # This could be made better, but for now let's just assert that we see the advanced modules mentioned in the page diff --git a/cms/templates/container.html b/cms/templates/container.html index 4f2cc15da9..75b11c8241 100644 --- a/cms/templates/container.html +++ b/cms/templates/container.html @@ -13,28 +13,28 @@ import json from contentstore.views.helpers import xblock_studio_url, xblock_type_display_name from django.utils.translation import ugettext as _ %> -<%block name="title">${xblock.display_name_with_default} ${xblock_type_display_name(xblock)}%block> +<%block name="title">${xblock.display_name_with_default} ${xblock_type_display_name(xblock) | h}%block> <%block name="bodyclass">is-signedin course container view-container%block> <%namespace name='static' file='static_content.html'/> <%block name="header_extras"> % for template_name in templates: - % endfor - + %block> <%block name="requirejs"> require(["js/factories/container"], function(ContainerFactory) { ContainerFactory( ${component_templates | n}, ${json.dumps(xblock_info) | n}, - "${action}", + "${action | h}", { isUnitPage: ${json.dumps(is_unit_page)}, canEdit: true @@ -55,7 +55,7 @@ from django.utils.translation import ugettext as _ ancestor_url = xblock_studio_url(ancestor) %> % if ancestor_url: - ${ancestor.display_name_with_default | h} + ${ancestor.display_name_with_default | h} % else: % endif @@ -72,12 +72,12 @@ from django.utils.translation import ugettext as _
${_("Select a component type under {em_start}Add New Component{em_end}. Then select a template.").format(em_start='', em_end="")}
+${_("Select a component type under {em_start}Add New Component{em_end}. Then select a template.").format(em_start='', em_end="") | h}
${_("The new component is added at the bottom of the page or group. You can then edit and move the component.")}
${_("Click the {em_start}Edit{em_end} icon in a component to edit its content.").format(em_start='', em_end="")}
+${_("Click the {em_start}Edit{em_end} icon in a component to edit its content.").format(em_start='', em_end="") | h}
${_("Drag components to new locations within this component.")}
${_("For content experiments, you can drag components to other groups.")}
@@ -121,7 +121,7 @@ from django.utils.translation import ugettext as _${_("Confirm that you have properly configured content in each of your experiment groups.")}
${_("You can keep working for a higher grade, or request your certificate now.")}
- ${section['format']} + ${section['format'] | h} %if section.get('due') is not None: <% @@ -194,7 +194,7 @@ from django.utils.http import urlquote_plus due_date = '' if len(formatted_string)==0 else _(u'due {date}').format(date=formatted_string) %> - ${due_date} + ${due_date | h} %endif
@@ -204,7 +204,7 @@ from django.utils.http import urlquote_plus