Skip to content

TNL-3429: implement display_name_with_default for studio text sanitation - #11697

Merged
Kelketek merged 2 commits into
openedx:masterfrom
open-craft:agaylard/TNL-3429-D
Mar 4, 2016
Merged

TNL-3429: implement display_name_with_default for studio text sanitation#11697
Kelketek merged 2 commits into
openedx:masterfrom
open-craft:agaylard/TNL-3429-D

Conversation

@Kelketek

Copy link
Copy Markdown
Contributor

JIRA tickets: TNL-3429

Discussion:
This PR replaces https://github.com/edx/edx-platform/pull/11588. It builds on work done by @robrap in https://github.com/edx/edx-platform/pull/10962, for TNL-3425.

These changes aim to follow https://openedx.atlassian.net/wiki/display/TNL/XSS+Protection .

The change to cms/templates/container.html replaces calls to display_name_with_default_escaped, which is deprecated and does not properly perform HTML-escaping, with display_name_with_default, which makes use of the |h filter for escaping.

The changes to these three files selectively apply escaping, using either the deprecated display_name_with_default_escaped or the preferred display_name_with_default, depending on the context, so that only the course outline and unit pages get the non-escaped data:

  • cms/djangoapps/contentstore/views/component.py
  • cms/djangoapps/contentstore/views/course.py
  • cms/djangoapps/contentstore/views/item.py

These two templates are changed to HTML-escape the display name fields:

  • cms/templates/js/course-outline.underscore
  • cms/templates/js/unit-outline.underscore

Dependencies: None

Sandbox: LMS Studio

Testing instructions:
Note: in the screenshots, the fields of interest are highlighted in purple.

  1. Start up Studio as the edxapp user: "paver devstack studio".
  2. Open a browser to Studio: http://127.0.0.1:8001. The home page loads.
  3. Click the "Sign in" button. The sign in page loads.
  4. Sign in as as the "staff@example.com" user.
  5. Click on "edX Demonstration Course". This opens the course outline page.
  6. Scroll to the bottom of the page.
  7. Click "New Section" and create a section named §: Intro to <HTML> & "JS"
  8. Click "New Subsection" and create a subsection named §§: Intro to <HTML> & "JS". Both names are rendered correctly on the course outline page.
    outline-page-loaded-before
  9. If necessary, click on the triangle alongside the subsection name to expand the field.
  10. Click "New Unit". The unit page loads.
  11. Without the fix, this reproduces bug TNL-3429:
    unit-page-loaded-before
  12. With the fix, the text is rendered correctly:
    unit-page-loaded-after
  13. Return to the course outline page. Click to edit the section name. Without the fix, the text is rendered in the text-field incorrectly (the < and > characters are HTML-escaped, but not the & and " characters, which appear as expected; the partial escaping is obvious with this particular test-data):
    outline-page-edited-before

With these changes, the text is rendered as correctly:
outline-page-edit-after

This editing bug occurs on the unit page too, and is also fixed by this change. I am not aware of any JIRA ticket tracking this issue.

Author notes and concerns:
This PR changes the way that display_name text is sent via JSON. Previously, the < and > characters would be escaped to &lt; and &gt;. No other HTML-sensitive characters were handled. Now, these characters are sent as-is. For the course outline page and the unit page, the escaping to HTML is performed on the browser by the underscore templates (properly, not just for angle-brackets).

Reviewers

@openedx-webhooks

Copy link
Copy Markdown

Thanks for the pull request, @Kelketek! It looks like you're a member of a company that does contract work for edX. If you're doing this work as part of a paid contract with edX, you should talk to edX about who will review this pull request. If this work is not part of a paid contract with edX, then you should ensure that there is an OSPR issue to track this work in JIRA, so that we don't lose track of your pull request.

To automatically create an OSPR issue for this pull request, just visit this link: https://openedx-webhooks.herokuapp.com/github/process_pr?number=11697&repo=edx%2Fedx-platform

@Kelketek

Kelketek commented Mar 1, 2016

Copy link
Copy Markdown
Contributor Author

@smarnach The only required note I saw on the previous copy of this PR was to change a straggling template. Can you confirm, and that this PR addresses that note?

@Kelketek Kelketek mentioned this pull request Mar 1, 2016
1 task
@smarnach

smarnach commented Mar 1, 2016

Copy link
Copy Markdown
Contributor

@Kelketek I went through all the comments as well, and as far as I can tell this one was the only one still needing attention. You addressed the point mentioned in the second paragraph of that comment. I can't tell whether you followed the suggestion in the last paragraph. If you did, I think you can ping upstream again on TNL-3429 (and point them to the new PR).

@robrap

robrap commented Mar 3, 2016

Copy link
Copy Markdown
Contributor

Thanks @Kelketek @smarnach. I've got the same open questions, so looking for confirmation.

Also, I'm hoping to land the following PR tomorrow, which hits the changes in container.html, but uses the page directive to make the entire template safe by default: https://github.com/edx/edx-platform/pull/11638/files

@Kelketek

Kelketek commented Mar 3, 2016

Copy link
Copy Markdown
Contributor Author

@robrap I did find a straggling issue or two, which I made commits for. But the items you mentioned seem to work correctly now after updating that template, and the extra issue I found with the xblock display name label in studio (which you can check by loading up a new HTML block and setting its display name to have extra characters)

@robrap

robrap commented Mar 4, 2016

Copy link
Copy Markdown
Contributor

@Kelketek This is good to go. 👍

When you rebase/squash to resolve conflicts, you should just be able to accept all my changes for cms/templates/container.html. FYI: there are no | h filters because it is handled at the top of the file. This is going to be the best practice going forward.

@Kelketek
Kelketek force-pushed the agaylard/TNL-3429-D branch from e3a0208 to 4c110c3 Compare March 4, 2016 19:37
@Kelketek
Kelketek force-pushed the agaylard/TNL-3429-D branch from 4c110c3 to f1c1c7c Compare March 4, 2016 19:38
@Kelketek

Kelketek commented Mar 4, 2016

Copy link
Copy Markdown
Contributor Author

@smarnach As this is a new PR, I will still need your explicit +1 on this. It has been rebased and should be ready for merge if tests pass and I have your OK.

@robrap

robrap commented Mar 4, 2016

Copy link
Copy Markdown
Contributor

@Kelketek I still think this looks good, but was searching around to make sure we weren't missing anything. Can you confirm if you manually tested in a content library? I think this is ultimately again using studio_xblock_wrapper.html, but it was hard to follow. Thanks.

@Kelketek

Kelketek commented Mar 4, 2016

Copy link
Copy Markdown
Contributor Author

@robrap Yes, I have checked. Just went to double-check. It does seem to work correctly.

@robrap

robrap commented Mar 4, 2016

Copy link
Copy Markdown
Contributor

Sounds good. Feel free to merge with a second thumb. Thank you.

@smarnach

smarnach commented Mar 4, 2016

Copy link
Copy Markdown
Contributor

👍

Kelketek added a commit that referenced this pull request Mar 4, 2016
TNL-3429: implement display_name_with_default for studio text sanitation
@Kelketek
Kelketek merged commit 04cadf7 into openedx:master Mar 4, 2016
@Kelketek
Kelketek deleted the agaylard/TNL-3429-D branch March 4, 2016 23:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants