#64886 closed defect (bug) (fixed)
Media: Remove `IMG` from cross-origin isolation `crossorigin="anonymous"` injection.
| Reported by: | adamsilverstein | Owned by: | adamsilverstein |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.0 |
| Component: | Media | Version: | 7.0 |
| Severity: | normal | Keywords: | has-patch has-unit-tests commit |
| Cc: | Focuses: |
Description
Description
In #64766, Document-Isolation-Policy: isolate-and-credentialless was introduced to enable cross-origin isolation for client-side media processing. As part of that change, wp_add_crossorigin_attributes() injects crossorigin="anonymous" on several HTML elements including IMG.
However, under Document-Isolation-Policy: isolate-and-credentialless, the browser's credentialless mode already handles cross-origin image loading without requiring CORS headers on the remote server. When crossorigin="anonymous" is explicitly added to an <img> element, it overrides this behavior and forces a CORS preflight request. If the remote server does not include Access-Control-Allow-Origin in its response headers, the image fails to load entirely.
This causes image previews to break in the block editor sidebar when an image block references an external URL from a server that does not serve CORS headers. For example, https://placehold.jp/1024x768.jpg triggers this bug.
Steps to reproduce
- Open the block editor (WordPress 7.0, Chromium 137+).
- Add an Image block.
- Select "Insert from URL" and enter an external image URL that does not serve CORS headers (e.g.
https://placehold.jp/1024x768.jpg). - Observe that the sidebar image preview fails to render with a CORS error in the console.
Expected behavior
The image preview should render. Under Document-Isolation-Policy: isolate-and-credentialless, the browser handles cross-origin images in credentialless mode without needing explicit CORS headers.
Actual behavior
The image fails to load because crossorigin="anonymous" forces a CORS request, and the remote server does not include the required Access-Control-Allow-Origin header.
Proposed fix
Remove IMG (and the related imagesrcset handling on LINK elements) from the $cross_origin_tag_attributes array in wp_add_crossorigin_attributes(). The other elements (AUDIO, VIDEO, SCRIPT, LINK, SOURCE) still need the attribute for proper error reporting, media processing, and font loading.
The corresponding client-side JavaScript change (removing img from the MutationObserver in @wordpress/block-editor) is handled in the Gutenberg PR.
Change History (7)
This ticket was mentioned in PR #11291 on WordPress/wordpress-develop by @adamsilverstein.
8 months ago
#2
- Keywords has-unit-tests added
@adamsilverstein commented on PR #11291:
8 months ago
#4
Added a proposed commit message to the PR description.
@westonruter commented on PR #11291:
8 months ago
#5
Why are images the one exception that don't need crossorign=anonymous? Why don't VIDEO, AUDIO, et al specifically _not_ require it?
Trac ticket: https://core.trac.wordpress.org/ticket/64886
Related Gutenberg issue: https://github.com/WordPress/gutenberg/issues/76476
## Description
Removes
IMGfrom the list of elements that receivecrossorigin="anonymous"inwp_add_crossorigin_attributes(). Also removes the relatedimagesrcsethandling fromLINKelements.Under
Document-Isolation-Policy: isolate-and-credentialless(introduced in r61844), the browser's credentialless mode already handles cross-origin image loading without requiring CORS headers on the remote server. Explicitly addingcrossorigin="anonymous"to<img>elements overrides this behavior and forces a CORS preflight — breaking images from servers that don't includeAccess-Control-Allow-Originin their response headers.This causes image previews to break in the block editor sidebar when an image block references an external URL (e.g.
https://placehold.jp/1024x768.jpg).Related Gutenberg PR: https://github.com/WordPress/gutenberg/pull/76618
## Changes
IMGentry from$cross_origin_tag_attributesinwp_add_crossorigin_attributes()imagesrcsetfromLINKentry (used for<link>preload tags for images — same issue)<script>instead of<img>for the positive case<img>does NOT getcrossorigin="anonymous"## Testing
https://placehold.jp/1024x768.jpgDocument-Isolation-Policy: isolate-and-credentiallessheader is still sent