You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Media library previews broken for offloaded media: crossorigin forced onto IMG in media templates #80535
gutenberg_override_media_templates() in lib/media/load.php adds crossorigin="anonymous" to every img tag in the Backbone media templates via a plain str_replace. Under Document-Isolation-Policy: isolate-and-credentialless the browser already loads cross-origin images in credentialless mode, so forcing the attribute triggers a CORS request that fails for images served without Access-Control-Allow-Origin headers - breaking media library previews for offloaded/CDN media.
#76618 removed img from gutenberg_add_crossorigin_attributes() and the editor content hook for exactly this reason, but missed this third injection path. The stale img entry was then carried into Core's wp_print_media_templates() by the client-side media processing backport, producing the WP 7.1beta2 regression reported on Trac.
Two additional problems with the str_replace approach:
On WordPress 7.1, where Core now injects the attribute itself, the plugin produces literal duplicates: <img crossorigin="anonymous" crossorigin="anonymous" …>.
With the plugin active, fixing Core alone changes nothing - the plugin re-adds the attribute.
Step-by-step reproduction instructions
Serve media from a host without CORS headers (e.g. filter wp_prepare_attachment_for_js to rewrite url/sizes[*].url to an external host).
Chrome ≥ 137, HTTPS or localhost (so DIP is active), Gutenberg plugin enabled.
Open the post editor → Image block → Media Library.
Grid thumbnails fail to load; console shows CORS errors for the image requests.
Expected behaviour
Media library previews load. img tags in the media templates carry no crossorigin attribute; audio/video keep it (needed for media processing), without duplicates on WP 7.1.
Activity