diff --git a/lms/djangoapps/shoppingcart/tests/test_views.py b/lms/djangoapps/shoppingcart/tests/test_views.py index 0a5cd7bf99..2dbe338c78 100644 --- a/lms/djangoapps/shoppingcart/tests/test_views.py +++ b/lms/djangoapps/shoppingcart/tests/test_views.py @@ -1824,11 +1824,11 @@ class RegistrationCodeRedemptionCourseEnrollment(SharedModuleStoreTestCase): RegistrationCodeRedemption.objects.filter(registration_code__code=registration_code) response = self.client.get(redeem_url) self.assertEquals(len(RegistrationCodeRedemption.objects.filter(registration_code__code=registration_code)), 1) - self.assertIn("You've clicked a link for an enrollment code that has already been used.", response.content) + self.assertIn("You've clicked a link for an enrollment code that has already been used.", response.content) #now check that the registration code has already been redeemed response = self.client.post(redeem_url) - self.assertIn("You've clicked a link for an enrollment code that has already been used.", response.content) + self.assertIn("You've clicked a link for an enrollment code that has already been used.", response.content) #now check the response of the dashboard page dashboard_url = reverse('dashboard') diff --git a/lms/envs/common.py b/lms/envs/common.py index f4815f3c50..e221bbc212 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -2305,6 +2305,7 @@ INSTALLED_APPS = [ # edx-drf-extensions 'csrf.apps.CsrfAppConfig', # Enables frontend apps to retrieve CSRF tokens. + 'xss_utils' ] ######################### CSRF ######################################### diff --git a/lms/templates/admin/base_site.html b/lms/templates/admin/base_site.html index d050919de3..4b36642f6b 100644 --- a/lms/templates/admin/base_site.html +++ b/lms/templates/admin/base_site.html @@ -7,13 +7,13 @@ {% block nav-global %}{% endblock %} {% block userlinks %} {% if site_url %} - {% trans 'View site' %} / + {% trans 'View site' as tmsg%}{{tmsg|force_escape}} / {% endif %} {% if user.is_active and user.is_staff %} {% url 'django-admindocs-docroot' as docsroot %} {% if docsroot %} - {% trans 'Documentation' %} / + {% trans 'Documentation' as tmsg%}{{tmsg|force_escape}} / {% endif %} {% endif %} - {% trans 'Log out' %} + {% trans 'Log out' as tmsg%}{{tmsg|force_escape}} {% endblock %} diff --git a/lms/templates/admin/user_api/accounts/cancel_retirement_action.html b/lms/templates/admin/user_api/accounts/cancel_retirement_action.html index e90a6dc555..07be7dc3e1 100644 --- a/lms/templates/admin/user_api/accounts/cancel_retirement_action.html +++ b/lms/templates/admin/user_api/accounts/cancel_retirement_action.html @@ -10,12 +10,14 @@ {% if form.non_field_errors|length > 0 %}

- {% trans "Please correct the errors below." %} + {% trans "Please correct the errors below." as tmsg %}{{tmsg|force_escape}}

{{ form.non_field_errors }} {% endif %} + {% filter force_escape %} {% blocktrans with username=retirement.user.username %}Are you sure you want to cancel retirement for user "{{ username }}"? {% endblocktrans %} + {% endfilter %}
{% for field in form %} @@ -33,7 +35,7 @@
- +
diff --git a/lms/templates/edit_unit_link.html b/lms/templates/edit_unit_link.html index e8c0988757..6b507c1945 100644 --- a/lms/templates/edit_unit_link.html +++ b/lms/templates/edit_unit_link.html @@ -1,6 +1,7 @@ +<%page expression_filter="h"/> <%! from django.utils.translation import ugettext as _ %>
${_("View Unit in Studio")}
-${frag_content} \ No newline at end of file +${frag_content | n, decode.utf8} diff --git a/lms/templates/logout.html b/lms/templates/logout.html index 29e0237634..66dca3ee3d 100644 --- a/lms/templates/logout.html +++ b/lms/templates/logout.html @@ -1,15 +1,17 @@ {% extends "main_django.html" %} {% load i18n staticfiles %} +{% load django_markup %} -{% block title %}{% trans "Signed Out" %} | {{ block.super }}{% endblock %} +{% block title %}{% trans "Signed Out" as tmsg %} | {{ tmsg | force_escape }} | {{ block.super }}{% endblock %} {% block body %} -

{% trans "You have signed out." %}

+

{% trans "You have signed out." as tmsg %} | {{ tmsg | force_escape }}

- {% blocktrans trimmed %} - If you are not redirected within 5 seconds, click here to go to the home page. + {% blocktrans trimmed asvar signout_msg1 %} + If you are not redirected within 5 seconds, {start_anchor}click here to go to the home page{end_anchor}. {% endblocktrans %} + {% interpolate_html signout_msg1 start_anchor=''|safe end_anchor=''|safe %}

- ${_('Required fields are noted by bold text and an asterisk (*).')} + ${Text(_('Required fields are noted by {strong_start}bold text and an asterisk (*){strong_end}.')).format( + strong_start=HTML(''), + strong_end=HTML('')),}

@@ -159,9 +164,9 @@ import calendar
- +
% endif @@ -171,17 +176,17 @@ import calendar <% honor_code_path = marketing_link('HONOR') %> - +
% if course_id and enrollment_action: - - + + % endif
diff --git a/lms/templates/register.html b/lms/templates/register.html index b95c83304c..2437d9f936 100644 --- a/lms/templates/register.html +++ b/lms/templates/register.html @@ -1,8 +1,10 @@ +<%page expression_filter="h"/> <%inherit file="main.html" /> <%namespace name='static' file='static_content.html'/> <%namespace file='main.html' import="login_query"/> <%! from django.utils.translation import ugettext as _ +from openedx.core.djangolib.js_utils import js_escaped_string from django.urls import reverse from django.utils import html from django_countries import countries @@ -52,14 +54,14 @@ import calendar }); $('#register-form').on('ajax:success', function(event, json, xhr) { - var nextUrl = "${login_redirect_url}"; + var nextUrl = "${login_redirect_url | n, js_escaped_string}"; if (json.redirect_url) { nextUrl = json.redirect_url; // Most likely third party auth completion. This trumps 'nextUrl' above. } if (!isExternal(nextUrl)) { location.href=nextUrl; } else { - location.href="${reverse('dashboard')}"; + location.href="${reverse('dashboard') | n, js_escaped_string}"; } }); @@ -67,7 +69,7 @@ import calendar toggleSubmitButton(true); json = $.parseJSON(jqXHR.responseText); $('.status.message.submission-error').addClass('is-shown').focus(); - $('.status.message.submission-error .message-copy').html(json.value).stop().css("display", "block"); + $('.status.message.submission-error .message-copy').text(json.value).stop().css("display", "block"); $(".field-error").removeClass('field-error'); $("[data-field='"+json.field+"']").addClass('field-error') }); @@ -86,13 +88,13 @@ import calendar removeClass('is-disabled'). attr('aria-disabled', false). prop('disabled', false). - html("${_('Create My {platform_name} Account').format(platform_name=platform_name)}"); + text("${_('Create My {platform_name} Account').format(platform_name=platform_name) | n, js_escaped_string}"); } else { $submitButton. addClass('is-disabled'). prop('disabled', true). - text("${_('Processing your account information')}"); + text("${_('Processing your account information') | n, js_escaped_string}"); } } diff --git a/lms/templates/resubscribe.html b/lms/templates/resubscribe.html index ac924d57ff..c635d5d3c0 100644 --- a/lms/templates/resubscribe.html +++ b/lms/templates/resubscribe.html @@ -1,6 +1,8 @@ +<%page expression_filter="h"/> <%! from django.urls import reverse from django.utils.translation import ugettext as _ +from openedx.core.djangolib.markup import HTML, Text from django.conf import settings %> <%inherit file="main.html" /> @@ -14,11 +16,11 @@ from django.conf import settings

- ${_("You have re-enabled forum notification emails from {platform_name}. " - "You may {dashboard_link_start}return to your dashboard{link_end}.").format( + ${Text(_("You have re-enabled forum notification emails from {platform_name}. " + "You may {dashboard_link_start}return to your dashboard{link_end}.")).format( platform_name=settings.PLATFORM_NAME, - dashboard_link_start="".format(reverse('dashboard')), - link_end="",)} + dashboard_link_start=HTML("").format(reverse('dashboard')), + link_end=HTML(""),)}

diff --git a/lms/templates/shoppingcart/registration_code_redemption.html b/lms/templates/shoppingcart/registration_code_redemption.html index 6ea7a9efb1..a9a6d42a20 100644 --- a/lms/templates/shoppingcart/registration_code_redemption.html +++ b/lms/templates/shoppingcart/registration_code_redemption.html @@ -1,5 +1,7 @@ +<%page expression_filter="h"/> <%! from django.utils.translation import ugettext as _ +from openedx.core.djangolib.markup import HTML, Text from django.urls import reverse from openedx.core.lib.courses import course_image_url %> @@ -20,34 +22,34 @@ from openedx.core.lib.courses import course_image_url ${_(
- ${_("Confirm your enrollment for: {span_start}course dates{span_end}").format( - span_start='', - span_end='' - )} + ${Text(_("Confirm your enrollment for: {span_start}course dates{span_end}")).format( + span_start=HTML(''), + span_end=HTML('') + )}

- ${course.display_name | h} + ${course.display_name}


% if reg_code_already_redeemed: - ${_( + ${Text(_( "You've clicked a link for an enrollment code that has already " "been used. Check your {link_start}course dashboard{link_end} " "to see if you're enrolled in the course, or contact your " "company's administrator." - ).format( - link_start=u''.format(url=reverse('dashboard')), - link_end='', + )).format( + link_start=HTML(u'').format(url=reverse('dashboard')), + link_end=HTML(''), )} % elif redemption_success: ${_( @@ -55,15 +57,15 @@ from openedx.core.lib.courses import course_image_url "This course has now been added to your dashboard." ).format( course_name=course.display_name, - ) | h} + )} % elif registered_for_course: - ${_( + ${Text(_( "You're already enrolled for this course. " "Visit your {link_start}dashboard{link_end} to see the course." - ).format( - link_start=u''.format(url=reverse('dashboard')), - link_end='', - )} + )).format( + link_start=HTML(u'').format(url=reverse('dashboard')), + link_end=HTML(''), + )} % elif redeem_code_error: ${_( "There was an error processing your redeem code.")} % else: @@ -75,7 +77,7 @@ from openedx.core.lib.courses import course_image_url ).format( course_name=course.display_name, site_name=site_name, - ) | h} + )} % endif

diff --git a/lms/templates/signup_modal.html b/lms/templates/signup_modal.html index 0b5cc19f1b..223fffb318 100644 --- a/lms/templates/signup_modal.html +++ b/lms/templates/signup_modal.html @@ -1,5 +1,8 @@ +<%page expression_filter="h"/> <%namespace name='static' file='static_content.html'/> <%! +from openedx.core.djangolib.markup import HTML, Text +from openedx.core.djangolib.js_utils import js_escaped_string from django.conf import settings from django.urls import reverse from django_countries import countries @@ -21,8 +24,8 @@ import calendar

- ${_('Sign Up for {platform_name}').format( - platform_name=u'{}'.format(settings.PLATFORM_NAME) + ${Text(_('Sign Up for {platform_name}')).format( + platform_name=HTML(u'{}').format(settings.PLATFORM_NAME) )}


@@ -47,7 +50,10 @@ import calendar % else: -

${_('Welcome {name}').format(name=extauth_id)}


+

${Text(_('{start_li}Welcome{end_li} {name}')).format( + start_li=HTML(''), + end_li=HTML(''), + name=extauth_id)}


${_('Enter a public username:')}

@@ -127,17 +133,17 @@ import calendar
% if settings.REGISTRATION_EXTRA_FIELDS['honor_code'] != 'hidden': % endif
@@ -162,12 +168,12 @@ import calendar