Media: Exclude IMG from crossorigin injection in media templates#12615
Media: Exclude IMG from crossorigin injection in media templates#12615itzmekhokan wants to merge 1 commit into
Conversation
When the client-side media processing feature was re-introduced, `wp_print_media_templates()` began adding `crossorigin="anonymous"` to `AUDIO`, `IMG`, and `VIDEO` tags inside the media manager Backbone templates. This reintroduced, for the media library picker, the exact issue fixed for `wp_add_crossorigin_attributes()` in [62048]. Under `Document-Isolation-Policy: isolate-and-credentialless` the browser already loads cross-origin images in credentialless mode without CORS headers. Forcing `crossorigin="anonymous"` on `IMG` triggers a CORS request that breaks previews of images served without `Access-Control-Allow-Origin` headers, such as media offloaded to a CDN. Remove `IMG` from the injected tags so it matches `wp_add_crossorigin_attributes()`, and add a regression test. Follow-up to #64886. Fixes #65673.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Media library picker previews break for media served from a CDN (or any host without CORS headers) because
wp_print_media_templates()injects crossorigin="anonymous" on IMG tags in the media manager Backbone templates.What the problem was:
wp_print_media_templates()began adding crossorigin="anonymous" to AUDIO, IMG, and VIDEO tags in the media templates.wp_add_crossorigin_attributes()in [62048] (#64886).What the fix does:
wp_print_media_templates(), so it matcheswp_add_crossorigin_attributes().Approach and why:
Trac ticket: https://core.trac.wordpress.org/ticket/65673
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 4.8
Used for: Ticket analysis, writing the unit tests, and PR Description. All changes were reviewed by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.