edx-platform icon indicating copy to clipboard operation
edx-platform copied to clipboard

fix: fixed embedded video not showing in about page

Open Asespinel opened this issue 2 months ago • 1 comments

Description

Fixes issue where embedded videos (YouTube iframes) appear correctly in Studio course about page preview but are stripped out and don't render in the LMS course about page. The issue was introduced by the lxml upgrade from 4.9.4 to 5.3.2.

In lxml 5.0+, the lxml.html.clean module was deprecated and moved to the separate lxml-html-clean package, which has different default behaviors.

Problem

The clean_dangerous_html() function in openedx/core/djangolib/markup.py uses lxml.html.clean.Cleaner which by default removes <iframe> elements for security reasons. This causes embedded videos to be stripped from course about pages when viewed in the LMS, even though they appear correctly in Studio preview.

Observed behavior:

  • Course about page HTML with YouTube iframe displays correctly in Studio
  • Same HTML is cleaned when rendered in LMS, removing the iframe
  • Users see empty space where video should be

Solution

Use host_whitelist with configurable allowed domains via the ALLOWED_EMBED_HOSTS Django setting.

Implementation:

  • Added ALLOWED_EMBED_HOSTS setting in lms/envs/common.py
  • Modified clean_dangerous_html() to read allowed hosts from settings only
  • No hardcoded defaults in the function - configuration is explicit in settings
  • If ALLOWED_EMBED_HOSTS is not configured or empty, all iframes are blocked

Default configuration (in lms/envs/common.py):

ALLOWED_EMBED_HOSTS = [
    'youtube.com',
    'www.youtube.com',
    'youtube-nocookie.com',
    'www.youtube-nocookie.com',
    'youtu.be',
    'vimeo.com',
    'player.vimeo.com',
]

Administrators can override this in production settings or via Tutor configuration.

Testing

  1. Create a course in Studio
  2. Add YouTube embed iframe to course about page
  3. Verify video appears in Studio preview
  4. Navigate to course about page in LMS
  5. Confirm video now renders correctly in LMS

The HTML used for the test is:

<h1>Hello, World!</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
<div class="tiny-pageembed" style="width: 800px; height: 800px;"><iframe src="https://www.youtube.com/embed/9C8YTP75HpA?si=jW9BPxEhDyVp14bb" 560="" height="800px" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen="" iframe="" width="800px" scrolling="no"></iframe></div>

Before

image

After

image

Related issue:

https://github.com/openedx/edx-platform/issues/37655

Asespinel avatar Nov 27 '25 02:11 Asespinel