Skip to content

Conversation

@Asespinel
Copy link
Contributor

@Asespinel Asespinel commented Nov 27, 2025

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:

#37655

@openedx-webhooks
Copy link

Thanks for the pull request, @Asespinel!

This repository is currently maintained by @openedx/wg-maintenance-edx-platform.

Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review.

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.
🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads
🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

Details
Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@mphilbrick211 mphilbrick211 moved this from Needs Triage to Waiting on Author in Contributions Dec 3, 2025
@mphilbrick211 mphilbrick211 moved this from Waiting on Author to Ready for Review in Contributions Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

open-source-contribution PR author is not from Axim or 2U

Projects

Status: Ready for Review

Development

Successfully merging this pull request may close these issues.

3 participants