Skip to content

Commit 9842837

Browse files
Media: Remove dead srcset handling in wp_add_crossorigin_attributes().
Every entry in the $cross_origin_tag_attributes map was flagged `false`, so the `if ( $is_srcset )` branch was never reachable; PHPStan reported it as always false. No tag enables srcset processing, and the cross-origin isolation tests assert that srcset-based cross-origin URLs are deliberately left untouched (img is not handled and link only checks href). Drop the unreachable branch and simplify the attribute map to a plain list of attributes. Behavior is unchanged and the full cross-origin isolation test suite still passes. Addresses review feedback on WordPress#11324
1 parent 74fa556 commit 9842837

1 file changed

Lines changed: 9 additions & 25 deletions

File tree

src/wp-includes/media.php

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6604,14 +6604,11 @@ function wp_add_crossorigin_attributes( string $html ): string {
66046604

66056605
// See https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes/crossorigin.
66066606
$cross_origin_tag_attributes = array(
6607-
'AUDIO' => array( 'src' => false ),
6608-
'LINK' => array( 'href' => false ),
6609-
'SCRIPT' => array( 'src' => false ),
6610-
'VIDEO' => array(
6611-
'src' => false,
6612-
'poster' => false,
6613-
),
6614-
'SOURCE' => array( 'src' => false ),
6607+
'AUDIO' => array( 'src' ),
6608+
'LINK' => array( 'href' ),
6609+
'SCRIPT' => array( 'src' ),
6610+
'VIDEO' => array( 'src', 'poster' ),
6611+
'SOURCE' => array( 'src' ),
66156612
);
66166613

66176614
while ( $processor->next_tag() ) {
@@ -6633,23 +6630,10 @@ function wp_add_crossorigin_attributes( string $html ): string {
66336630

66346631
$is_cross_origin = false;
66356632

6636-
foreach ( $cross_origin_tag_attributes[ $tag ] as $attr => $is_srcset ) {
6637-
if ( $is_srcset ) {
6638-
$srcset = $processor->get_attribute( $attr );
6639-
if ( is_string( $srcset ) ) {
6640-
foreach ( explode( ',', $srcset ) as $candidate ) {
6641-
$candidate_url = strtok( trim( $candidate, " \t\f\r\n" ), " \t\f\r\n" );
6642-
if ( is_string( $candidate_url ) && ! str_starts_with( $candidate_url, $site_url ) && ! str_starts_with( $candidate_url, '/' ) ) {
6643-
$is_cross_origin = true;
6644-
break;
6645-
}
6646-
}
6647-
}
6648-
} else {
6649-
$url = $processor->get_attribute( $attr );
6650-
if ( is_string( $url ) && ! str_starts_with( $url, $site_url ) && ! str_starts_with( $url, '/' ) ) {
6651-
$is_cross_origin = true;
6652-
}
6633+
foreach ( $cross_origin_tag_attributes[ $tag ] as $attr ) {
6634+
$url = $processor->get_attribute( $attr );
6635+
if ( is_string( $url ) && ! str_starts_with( $url, $site_url ) && ! str_starts_with( $url, '/' ) ) {
6636+
$is_cross_origin = true;
66536637
}
66546638

66556639
if ( $is_cross_origin ) {

0 commit comments

Comments
 (0)