Skip to content
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

Sustaining xss fixes #228

Merged
18 changes: 10 additions & 8 deletions cms/static/js/views/video/transcripts/file_uploader.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
define(
[
'jquery', 'backbone', 'underscore',
'js/views/video/transcripts/utils'
'js/views/video/transcripts/utils',
'edx-ui-toolkit/js/utils/html-utils'
],
function($, Backbone, _, TranscriptUtils) {
function($, Backbone, _, TranscriptUtils, HtmlUtils) {
'use strict';
var FileUploader = Backbone.View.extend({
invisibleClass: 'is-invisible',

Expand Down Expand Up @@ -37,9 +39,8 @@ function($, Backbone, _, TranscriptUtils) {

return;
}
this.template = _.template(tpl);

tplContainer.html(this.template({
this.template = HtmlUtils.template(tpl);
HtmlUtils.setHtml(tplContainer, this.template({
ext: this.validFileExtensions,
component_locator: this.options.component_locator
}));
Expand Down Expand Up @@ -126,11 +127,12 @@ function($, Backbone, _, TranscriptUtils) {
*
*/
checkExtValidity: function(file) {
var fileExtension;
if (!file.name) {
return void(0);
}

var fileExtension = file.name
fileExtension = file.name
.split('.')
.pop()
.toLowerCase();
Expand All @@ -153,7 +155,7 @@ function($, Backbone, _, TranscriptUtils) {

this.$progress
.width(percentVal)
.html(percentVal)
.text(percentVal)
.removeClass(this.invisibleClass);
},

Expand All @@ -177,7 +179,7 @@ function($, Backbone, _, TranscriptUtils) {

this.$progress
.width(percentVal)
.html(percentVal);
.text(percentVal);
},

/**
Expand Down
6 changes: 3 additions & 3 deletions cms/templates/admin/base_site.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ <h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('D
{% block nav-global %}{% endblock %}
{% block userlinks %}
{% if site_url %}
<a href="{{ site_url }}">{% trans 'View site' %}</a> /
<a href="{{ site_url }}">{% trans 'View site' as tmsg%} {{tmsg|force_escape}}</a> /
{% endif %}
{% if user.is_active and user.is_staff %}
{% url 'django-admindocs-docroot' as docsroot %}
{% if docsroot %}
<a href="{{ docsroot }}">{% trans 'Documentation' %}</a> /
<a href="{{ docsroot }}">{% trans 'Documentation' as tmsg %} {{tmsg|force_escape}}</a> /
{% endif %}
{% endif %}
<a href="{% url 'admin:logout' %}">{% trans 'Log out' %}</a>
<a href="{% url 'admin:logout' %}">{% trans 'Log out' as tmsg %} {{tmsg|force_escape}}</a>
{% endblock %}
2 changes: 1 addition & 1 deletion cms/templates/edit-tabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<%block name="page_bundle">
<%static:webpack entry="js/factories/edit_tabs">
EditTabsFactory("${context_course.location | n, js_escaped_string}", "${reverse('tabs_handler', kwargs={'course_key_string': context_course.id})}");
EditTabsFactory("${context_course.location | n, js_escaped_string}", "${reverse('tabs_handler', kwargs={'course_key_string': context_course.id}) | n, js_escaped_string}");
</%static:webpack>
</%block>

Expand Down
4 changes: 3 additions & 1 deletion cms/templates/manage_users_lib.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<%page expression_filter="h"/>

<%inherit file="base.html" />
<%!
from django.utils.translation import ugettext as _
Expand Down Expand Up @@ -110,7 +112,7 @@ <h3 class="title-3">${_("Library Access Roles")}</h3>
<%block name="requirejs">
require(["js/factories/manage_users_lib"], function(ManageLibraryUsersFactory) {
ManageLibraryUsersFactory(
"${context_library.display_name_with_default | h}",
"${context_library.display_name_with_default | n, js_escaped_string}",
${users | n, dump_js_escaped_json},
"${reverse('course_team_handler', kwargs={'course_key_string': library_key, 'email': '@@EMAIL@@'}) | n, js_escaped_string}",
${request.user.id | n, dump_js_escaped_json},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},

render: function() {
// xss-lint: disable=javascript-jquery-html
this.$el.html(_.template(this.template)({
enrollment: this.enrollment,
modes: this.modes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<td>
<button
class="change-enrollment-btn"
data-modes="<%= _.pluck(enrollment.get('course_modes'), 'slug')%>"
data-course_id="<%= enrollment.get('course_id') %>"
data-modes="<%- _.pluck(enrollment.get('course_modes'), 'slug')%>"
data-course_id="<%- enrollment.get('course_id') %>"
>
<%- gettext('Change Enrollment') %>
</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<abbr title="<%= date %>"></abbr>
<abbr title="<%- date %>"></abbr>
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<li class="team-member">
<a class="member-profile" href="<%= memberProfileUrl %>">
<img class="image-url" src="<%= imageUrl %>" alt="<%= username %>'s profile page" />
<a class="member-profile" href="<%= memberProfileUrl /* xss-lint: disable=underscore-not-escaped */%>">
<img class="image-url" src="<%= imageUrl /* xss-lint: disable=underscore-not-escaped */%>" alt="<%= username /* xss-lint: disable=underscore-not-escaped */%>'s profile page" />
</a>
<div class="member-info-container">
<span class="primary"><%= username %></span>
<span class="primary"><%= username /* xss-lint: disable=underscore-not-escaped */%></span>
<div class="secondary">
<span id="date-joined"><%= dateJoined %></span>
<span id="date-joined"><%= dateJoined /* xss-lint: disable=underscore-not-escaped */%></span>
<span> | </span>
<span id="last-active"><%= lastActive %></span>
<span id="last-active"><%= lastActive /* xss-lint: disable=underscore-not-escaped */%></span>
</div>
</div>
<button class="action-remove-member" data-username="<%= username %>">
<%- gettext("Remove") %><span class="sr">&nbsp;<%= username %></span>
<button class="action-remove-member" data-username="<%= username /* xss-lint: disable=underscore-not-escaped */%>">
<%- gettext("Remove") %><span class="sr">&nbsp;<%= username /* xss-lint: disable=underscore-not-escaped */%></span>
</button>
</li>
5 changes: 4 additions & 1 deletion lms/static/js/verify_student/views/pay_and_verify_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,10 @@ var edx = edx || {};
// Get or create the step container
$stepEl = $('#current-step-container');
if (!$stepEl.length) {
$stepEl = $('<div id="current-step-container"></div>').appendTo(this.el);
$stepEl = edx.HtmlUtils.append(
$(this.el),
edx.HtmlUtils.HTML('<div id="current-step-container"></div>').toString()
);
}

// Render the subview
Expand Down
5 changes: 4 additions & 1 deletion lms/static/js/verify_student/views/reverify_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@
// Get or create the step container
$stepEl = $('#current-step-container');
if (!$stepEl.length) {
$stepEl = $('<div id="current-step-container"></div>').appendTo(this.el);
$stepEl = edx.HtmlUtils.append(
$(this.el),
edx.HtmlUtils.HTML('<div id="current-step-container"></div>').toString()
);
}

// Render the step subview
Expand Down
2 changes: 1 addition & 1 deletion lms/static/js/views/file_uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
return optionVal || default_value;
},
submitButton, resultNotification;

// xss-lint: disable=javascript-jquery-html
this.$el.html(this.template({
title: get_option_with_default('title', ''),
inputLabel: get_option_with_default('inputLabel', ''),
Expand Down
20 changes: 11 additions & 9 deletions lms/static/js/views/image_field.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
(function(define) {
'use strict';
define([
'gettext', 'jquery', 'underscore', 'backbone', 'js/views/fields',
'gettext', 'jquery', 'underscore', 'backbone',
'edx-ui-toolkit/js/utils/html-utils', 'js/views/fields',
'text!templates/fields/field_image.underscore',
'backbone-super', 'jquery.fileupload'
], function(gettext, $, _, Backbone, FieldViews, field_image_template) {
], function(gettext, $, _, Backbone, HtmlUtils, FieldViews, FieldImageTemplate) {
var ImageFieldView = FieldViews.FieldView.extend({

fieldType: 'image',

fieldTemplate: field_image_template,
fieldTemplate: FieldImageTemplate,
uploadButtonSelector: '.upload-button-input',

titleAdd: gettext('Upload an image'),
Expand Down Expand Up @@ -44,7 +45,7 @@
},

render: function() {
this.$el.html(this.template({
var attributes = {
id: this.options.valueAttribute,
inputName: (this.options.inputName || 'file'),
imageUrl: _.result(this, 'imageUrl'),
Expand All @@ -54,7 +55,8 @@
removeButtonIcon: _.result(this, 'iconRemove'),
removeButtonTitle: _.result(this, 'removeButtonTitle'),
screenReaderTitle: _.result(this, 'screenReaderTitle')
}));
};
this.$el.html(HtmlUtils.HTML(this.template(attributes)).toString());
this.delegateEvents();
this.updateButtonsVisibility();
this.watchForPageUnload();
Expand Down Expand Up @@ -184,14 +186,14 @@

showUploadInProgressMessage: function() {
this.$('.u-field-upload-button').addClass('in-progress');
this.$('.upload-button-icon').html(this.iconProgress);
this.$('.upload-button-title').html(this.titleUploading);
HtmlUtils.setHtml(this.$('.upload-button-icon'), HtmlUtils.HTML(this.iconProgress));
HtmlUtils.setHtml(this.$('.upload-button-title'), HtmlUtils.HTML(this.titleUploading));
},

showRemovalInProgressMessage: function() {
this.$('.u-field-remove-button').css('opacity', 1);
this.$('.remove-button-icon').html(this.iconProgress);
this.$('.remove-button-title').html(this.titleRemoving);
HtmlUtils.setHtml(this.$('.remove-button-icon'), HtmlUtils.HTML(this.iconProgress));
HtmlUtils.setHtml(this.$('.remove-button-title'), HtmlUtils.HTML(this.titleRemoving));
},

setCurrentStatus: function(status) {
Expand Down
2 changes: 1 addition & 1 deletion lms/static/js/views/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},

render: function() {
this.$el.html(this.template({
this.$el.html(this.template({ // xss-lint: disable=javascript-jquery-html
type: this.model.get('type'),
title: this.model.get('title'),
message: this.model.get('message'),
Expand Down
2 changes: 1 addition & 1 deletion lms/templates/api_admin/api_access_request_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ <h1 id="api-header">
<div class="api-form-container">
<form action="" method="post" class="api-form">
<input type="hidden" id="csrf_token" name="csrfmiddlewaretoken" value="${csrf_token}">
${form.as_p() | n}
${form.as_p() | n, decode.utf8}
<input id="api-access-submit" type="submit" value="${_('Request API Access')}"/>
</form>
</div>
Expand Down
15 changes: 10 additions & 5 deletions lms/templates/split_test_author_view.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<%! from django.utils.translation import ugettext as _ %>
<%page expression_filter="h"/>

<%!
from django.utils.translation import ugettext as _
from openedx.core.djangolib.markup import HTML, Text
%>

<%
split_test = context.get('split_test')
Expand All @@ -11,8 +16,8 @@
<div class="xblock-message information">
<p>
<span class="message-text">
${_("This content experiment uses group configuration '{group_configuration_name}'.").format(
group_configuration_name="<a href='{}'>{}</a>".format(group_configuration_url, user_partition.name) if show_link else user_partition.name
${Text(_("This content experiment uses group configuration '{group_configuration_name}'.")).format(
group_configuration_name=Text(HTML("<a href='{}'>{}</a>")).format(group_configuration_url, user_partition.name) if show_link else user_partition.name
)}
</span>
</p>
Expand All @@ -23,13 +28,13 @@
% if is_root:
<div class="wrapper-groups is-active">
<h3 class="sr">${_("Active Groups")}</h3>
${active_groups_preview}
${HTML(active_groups_preview)}
</div>

% if inactive_groups_preview:
<div class="wrapper-groups is-inactive">
<h3 class="title">${_("Inactive Groups")}</h3>
${inactive_groups_preview}
${HTML(inactive_groups_preview)}
</div>
% endif
% endif
2 changes: 2 additions & 0 deletions themes/stanford-style/lms/templates/static_templates/tos.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## mako
<%page expression_filter="h"/>
<%!
from django.utils.translation import ugettext as _
%>
Expand Down Expand Up @@ -27,6 +28,7 @@ <h2 id="copyright">${_('Copyright')}</h2>
<script>
$(document).ready(function() {
var print_tos = '<input type="button" value="Print Terms of Service" class="print">';
// xss-lint: disable=javascript-jquery-prepend, javascript-jquery-append
$('#content section.tos').prepend(print_tos).append(print_tos);
$('#content section.tos input.print').click(function() {
window.print();
Expand Down