From 26091dcda1c20405b303a7bf7f7f6d5762083616 Mon Sep 17 00:00:00 2001 From: Shadi Naif Date: Thu, 17 Mar 2022 14:29:42 +0300 Subject: [PATCH 1/5] Security Patch - BLACK-1545 --- .../lib/xmodule/xmodule/backcompat_module.py | 10 ++-- .../xmodule/js/fixtures/imageinput.underscore | 16 +++--- .../xmodule/js/src/video/04_video_control.js | 2 +- .../js/capa/chemical_equation_preview.js | 11 +++- .../static/js/capa/drag_and_drop/targets.js | 56 +++++++++---------- .../js/components/header/views/header.js | 47 +++++++++------- lms/static/js/course_survey.js | 15 +++-- lms/static/js/customwmd.js | 4 +- lms/static/js/edxnotes/views/tab_item.js | 7 ++- lms/static/js/edxnotes/views/tab_panel.js | 12 ++-- lms/static/js/leanModal.js | 5 +- .../views/collection_list_view.js | 2 +- 12 files changed, 105 insertions(+), 82 deletions(-) diff --git a/common/lib/xmodule/xmodule/backcompat_module.py b/common/lib/xmodule/xmodule/backcompat_module.py index 7b0fa690fade..9e911ab9e3b3 100644 --- a/common/lib/xmodule/xmodule/backcompat_module.py +++ b/common/lib/xmodule/xmodule/backcompat_module.py @@ -7,6 +7,8 @@ from lxml import etree +from openedx.core.djangolib.markup import Text + from .x_module import XModuleDescriptor log = logging.getLogger(__name__) @@ -72,8 +74,8 @@ def from_xml(cls, xml_data, system, id_generator): the child element """ xml_object = etree.fromstring(xml_data) - system.error_tracker("WARNING: the <{0}> tag is deprecated. Please do not use in new content." - .format(xml_object.tag)) + system.error_tracker(Text("WARNING: the <{tag=}> tag is deprecated. Please do not use in new content.") + .format(tag=xml_object.tag)) if len(xml_object) == 1: for (key, val) in xml_object.items(): @@ -96,8 +98,8 @@ def from_xml(cls, xml_data, system, id_generator): """ xml_object = etree.fromstring(xml_data) - system.error_tracker('WARNING: the <{tag}> tag is deprecated. ' - 'Instead, use . ' + system.error_tracker(Text('WARNING: the <{tag}> tag is deprecated. ' + 'Instead, use . ') .format(tag=xml_object.tag)) tag = xml_object.tag diff --git a/common/lib/xmodule/xmodule/js/fixtures/imageinput.underscore b/common/lib/xmodule/xmodule/js/fixtures/imageinput.underscore index bafdd797c9a2..a6ec5dc894b8 100644 --- a/common/lib/xmodule/xmodule/js/fixtures/imageinput.underscore +++ b/common/lib/xmodule/xmodule/js/fixtures/imageinput.underscore @@ -2,24 +2,24 @@ -
+
-
+
@@ -27,8 +27,8 @@ Status: unanswered diff --git a/common/lib/xmodule/xmodule/js/src/video/04_video_control.js b/common/lib/xmodule/xmodule/js/src/video/04_video_control.js index f80c0edd9feb..fc6557160c94 100644 --- a/common/lib/xmodule/xmodule/js/src/video/04_video_control.js +++ b/common/lib/xmodule/xmodule/js/src/video/04_video_control.js @@ -154,7 +154,7 @@ var endTime = (this.config.endTime !== null) ? this.config.endTime : params.duration; // in case endTime is accidentally specified as being greater than the video endTime = Math.min(endTime, params.duration); - this.videoControl.vidTimeEl.html(Time.format(params.time) + ' / ' + Time.format(endTime)); + this.videoControl.vidTimeEl.text(Time.format(params.time) + ' / ' + Time.format(endTime)); } } ); diff --git a/common/static/js/capa/chemical_equation_preview.js b/common/static/js/capa/chemical_equation_preview.js index 85a1c2ac6780..d23d8e51d3f6 100644 --- a/common/static/js/capa/chemical_equation_preview.js +++ b/common/static/js/capa/chemical_equation_preview.js @@ -3,9 +3,16 @@ function create_handler(saved_div) { return (function(response) { if (response.error) { - saved_div.html("" + response.error + ''); + edx.HtmlUtils.setHtml( + saved_div, + edx.HtmlUtils.joinHtml( + edx.HtmlUtils.HTML(""), + response.error, + edx.HtmlUtils.HTML('') + ) + ); } else { - saved_div.html(response.preview); + saved_div.html(edx.HtmlUtils.HTML(response.preview).toString()); } }); } diff --git a/common/static/js/capa/drag_and_drop/targets.js b/common/static/js/capa/drag_and_drop/targets.js index ffbf47f1e8b9..a6787d3d5d5e 100644 --- a/common/static/js/capa/drag_and_drop/targets.js +++ b/common/static/js/capa/drag_and_drop/targets.js @@ -1,5 +1,5 @@ (function(requirejs, require, define) { - define([], function() { + define(['edx-ui-toolkit/js/utils/html-utils'], function(HtmlUtils) { return { initializeBaseTargets: initializeBaseTargets, initializeTargetField: initializeTargetField, @@ -76,17 +76,19 @@ } $targetEl = $( - '
' + HtmlUtils.joinHtml( + HtmlUtils.HTML('
') + ).toString() ); if (fromTargetField === true) { $targetEl.appendTo(draggableObj.iconEl); @@ -100,23 +102,17 @@ if (state.config.onePerTarget === false) { $numTextEl = $( - '
0
' - ); + HtmlUtils.joinHtml( + HtmlUtils.HTML('
0
') + ).toString() + ); } else { $numTextEl = null; } @@ -263,7 +259,7 @@ function updateNumTextEl() { if (this.numTextEl !== null) { - this.numTextEl.html(this.draggableList.length); + this.numTextEl.text(this.draggableList.length); } } }); // End-of: define([], function () { diff --git a/lms/static/js/components/header/views/header.js b/lms/static/js/components/header/views/header.js index 2c4ca3621126..0f584f5242d7 100644 --- a/lms/static/js/components/header/views/header.js +++ b/lms/static/js/components/header/views/header.js @@ -3,26 +3,33 @@ */ (function(define) { 'use strict'; - define(['backbone', 'text!templates/components/header/header.underscore'], - function(Backbone, headerTemplate) { - var HeaderView = Backbone.View.extend({ - initialize: function(options) { - this.template = _.template(headerTemplate); - this.headerActionsView = options.headerActionsView; - this.listenTo(this.model, 'change', this.render); - this.render(); - }, + define([ + 'backbone', + 'text!templates/components/header/header.underscore', + 'edx-ui-toolkit/js/utils/html-utils' + ], + function(Backbone, headerTemplate, HtmlUtils) { + var HeaderView = Backbone.View.extend({ + initialize: function(options) { + this.template = HtmlUtils.template(headerTemplate); + this.headerActionsView = options.headerActionsView; + this.listenTo(this.model, 'change', this.render); + this.render(); + }, - render: function() { - var json = this.model.attributes; - this.$el.html(this.template(json)); - if (this.headerActionsView) { - this.headerActionsView.setElement(this.$('.page-header-secondary')).render(); - } - return this; - } - }); + render: function() { + var json = this.model.attributes; + HtmlUtils.setHtml( + this.$el, + this.template(json) + ); + if (this.headerActionsView) { + this.headerActionsView.setElement(this.$('.page-header-secondary')).render(); + } + return this; + } + }); - return HeaderView; - }); + return HeaderView; + }); }).call(this, define || RequireJS.define); diff --git a/lms/static/js/course_survey.js b/lms/static/js/course_survey.js index 286cd26b13e5..90c65f09d89c 100644 --- a/lms/static/js/course_survey.js +++ b/lms/static/js/course_survey.js @@ -23,22 +23,25 @@ $(function() { var cancel_submit = false; $inputs.each(function() { + var val, fieldLabel; /* see if it is a required field and - if so - make sure user presented all information */ if (typeof $(this).attr('required') !== typeof undefined) { - var val = $(this).val(); + val = $(this).val(); if (typeof(val) === 'string') { if (val.trim().length === 0) { - var field_label = $(this).parent().find('label'); + fieldLabel = $(this).parent().find('label'); $(this).parent().addClass('field-error'); - $('.status.message.submission-error .message-copy').append("
  • " + field_label.text() + '
  • '); + // eslint-disable-next-line max-len + $('.status.message.submission-error .message-copy').append(edx.HtmlUtils.joinHtml(edx.HtmlUtils.HTML("
  • "), fieldLabel.text(), edx.HtmlUtils.HTML('
  • ')).toString()); cancel_submit = true; } } else if (typeof(val) === 'object') { /* for SELECT statements */ if (val === null || val.length === 0 || val[0] === '') { - var field_label = $(this).parent().find('label'); + fieldLabel = $(this).parent().find('label'); $(this).parent().addClass('field-error'); - $('.status.message.submission-error .message-copy').append("
  • " + field_label.text() + '
  • '); + // eslint-disable-next-line max-len + $('.status.message.submission-error .message-copy').append(edx.HtmlUtils.joinHtml(edx.HtmlUtils.HTML("
  • "), fieldLabel.text(), edx.HtmlUtils.HTML('
  • ')).toString()); cancel_submit = true; } } @@ -70,7 +73,7 @@ $(function() { json = $.parseJSON(jqXHR.responseText); $('.status.message.submission-error').addClass('is-shown').focus(); $('.status.message.submission-error .message-copy'). - html(gettext('There has been an error processing your survey.')). + text(gettext('There has been an error processing your survey.')). stop(). css('display', 'block'); }); diff --git a/lms/static/js/customwmd.js b/lms/static/js/customwmd.js index e0ad1b547324..0f4cfccaeecb 100644 --- a/lms/static/js/customwmd.js +++ b/lms/static/js/customwmd.js @@ -201,8 +201,8 @@ Mostly adapted from math.stackexchange.com: http://cdn.sstatic.net/js/mathjax-ed .append($("