Skip to content

Media library previews broken for offloaded media: crossorigin forced onto IMG in media templates #80535

Closed

Description

@adamsilverstein

Description

Gutenberg-plugin side of Trac #65673.

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

  1. 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).
  2. Chrome ≥ 137, HTTPS or localhost (so DIP is active), Gutenberg plugin enabled.
  3. Open the post editor → Image block → Media Library.
  4. 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

  1. added
    [Type] BugAn existing feature does not function as intended
    [Feature] MediaAnything that impacts the experience of managing media
    on Jul 21, 2026
  2. moved this from 🏗️ In Progress to 🔎 Needs Review in WordPress 7.1 Editor Taskson Jul 21, 2026
  3. moved this from 🔎 Needs Review to 🏗️ In Progress in WordPress 7.1 Editor Taskson Jul 22, 2026
  4. moved this from 🏗️ In Progress to ✅ Done in WordPress 7.1 Editor Taskson Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Feature] MediaAnything that impacts the experience of managing media[Type] BugAn existing feature does not function as intended

    Type

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions