-
Notifications
You must be signed in to change notification settings - Fork 2.9k
OEmbed providers: Tighten up resource URL matching for providers #21583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
c17821d to
20db9a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances security for OEmbed providers by tightening URL validation to prevent Server-Side Request Forgery (SSRF) attacks. The changes ensure that resource URLs are matched only on legitimate provider domains, not paths within untrusted domains.
Changes:
- Updated all OEmbed provider regex patterns to use anchored patterns starting with
^https?:\/\/, preventing path-based SSRF attacks - Added comprehensive test coverage for all providers with tests for valid URLs, SSRF protection, and unrelated URL rejection
- Refactored some providers to use generated regex for performance and extracted markup building logic for testability
- Removed unused
using System.Xml;statements from providers that don't directly use XML classes
Reviewed changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| OEmbedProviderTestBase.cs | New base class for provider tests that uses OEmbedService.MatchesUrlScheme |
| YouTubeEmbedProviderTests.cs | Tests for YouTube URL validation including SSRF protection |
| XEmbedProviderTests.cs | Tests for X/Twitter URL validation including SSRF protection |
| VimeoEmbedProviderTests.cs | Tests for Vimeo URL validation including SSRF protection |
| TedEmbedProviderTests.cs | Tests for TED URL validation including SSRF protection |
| SoundCloudEmbedProviderTests.cs | Tests for SoundCloud URL validation including SSRF protection |
| SlideshareEmbedProviderTests.cs | Tests for Slideshare URL validation including SSRF protection |
| LottieFilesEmbedProviderTests.cs | Tests for LottieFiles URL validation and markup building logic |
| KickstarterEmbedProviderTests.cs | Tests for Kickstarter URL validation including SSRF protection |
| IssuuEmbedProviderTests.cs | Tests for Issuu URL validation including SSRF protection |
| HuluEmbedProviderTests.cs | Tests for Hulu URL validation including SSRF protection |
| GiphyEmbedProviderTests.cs | Tests for Giphy URL validation including SSRF protection |
| GettyImagesEmbedProviderTests.cs | Tests for Getty Images URL validation including SSRF protection |
| FlickrEmbedProviderTests.cs | Tests for Flickr URL validation and markup building logic |
| DailyMotionEmbedProviderTests.cs | Tests for DailyMotion URL validation including SSRF protection |
| OEmbedService.cs | Extracted MatchesUrlScheme method as internal static for testability |
| Youtube.cs | Updated regex patterns to use anchored domain matching, added XML documentation |
| X.cs | Updated regex to use anchored domain matching, modern collection syntax, added XML documentation |
| Vimeo.cs | Updated regex to use anchored domain matching, removed unused using, added XML documentation |
| Ted.cs | Updated regex to use anchored domain matching, removed unused using, added XML documentation |
| SoundCloud.cs | Updated regex to use anchored domain matching, removed unused using, added XML documentation |
| Slideshare.cs | Updated regex to use anchored domain matching, removed unused using, added XML documentation |
| LottieFiles.cs | Updated regex to use anchored domain matching, extracted BuildMarkup for testing, uses generated regex, added XML documentation |
| Kickstarter.cs | Updated regex to use anchored domain matching, modern collection syntax, added XML documentation |
| Issuu.cs | Updated regex to use anchored domain matching, removed unused using, added XML documentation |
| Hulu.cs | Updated regex to use anchored domain matching, modern collection syntax, added XML documentation |
| Giphy.cs | Updated regex to use anchored domain matching, modern collection syntax, added XML documentation |
| GettyImages.cs | Updated regex to use anchored domain matching, modern collection syntax, added XML documentation |
| Flickr.cs | Updated regex to use anchored domain matching (removed flic.kr support), changed API endpoint to HTTPS, extracted BuildMarkup for testing, added XML documentation |
| DailyMotion.cs | Updated regex to use anchored domain matching, removed unused using, added XML documentation |
| UdiGetterExtensionsTests.cs | Added fully qualified type name to resolve ambiguity caused by new test file namespaces |
Description
This PR tightens up the validation on the matching of resource URLs to OEmbed providers, ensuring we only match on domains and not paths, ensuring only legitimate provider domains are matched.
We've also improved test coverage of these embed providers, adding tests for the URL matching logic as well as the building of markup for those providers with significant logic. Finally, some small optimisations were applied.
Testing
The unit tests should cover changes across the providers, so manual test of embedding into the RTE of a couple of providers should suffice.