fix: fixed embedded video not showing in about page
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_HOSTSsetting inlms/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_HOSTSis 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
- Create a course in Studio
- Add YouTube embed iframe to course about page
- Verify video appears in Studio preview
- Navigate to course about page in LMS
- 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
After
Related issue:
https://github.com/openedx/edx-platform/issues/37655