General: Remove `noopener` from links opening in a new tab.

Removes the automatic addition of `rel="noopener noreferrer"` from links targeting a new tab or window, `target='_blank'`. Since this was introduced, supported browsers have changed their security policies and no longer allow the opened link to have JavaScript access to the previous tab.

Deprecates:

* `wp_targeted_link_rel()`
* `wp_targeted_link_rel_callback()`
* `wp_init_targeted_link_rel_filters()`: converted to a noop function
* `wp_remove_targeted_link_rel_filters()`: converted to a noop function

The deprecated functions are retained in `formatting.php` as in `SHORTINIT` mode the file is included while `deprecated.php` is not.

This also removes the `noopener` from links hard coded within the WordPress dashboard linking to documentation and other resources.

Props audrasjb, azaozz, dhruval04, dorzki, neo2k23, presskopp, sabernhardt, swissspidy, tobiasbg.
Fixes #53843.

Built from https://develop.svn.wordpress.org/trunk@59120


git-svn-id: http://core.svn.wordpress.org/trunk@58516 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Peter Wilson 2024-09-30 05:19:16 +00:00
parent cf877c686b
commit 8c3dd2eb88
19 changed files with 36 additions and 70 deletions

View File

@ -746,7 +746,7 @@ class WP_Site_Health {
)
),
'actions' => sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
esc_url( wp_get_update_php_url() ),
__( 'Learn more about updating PHP' ),
/* translators: Hidden accessibility text. */
@ -892,7 +892,7 @@ class WP_Site_Health {
__( 'The WordPress Hosting Team maintains a list of those modules, both recommended and required, in <a href="%1$s" %2$s>the team handbook%3$s</a>.' ),
/* translators: Localized team handbook, if one exists. */
esc_url( __( 'https://make.wordpress.org/hosting/handbook/handbook/server-environment/#php-extensions' ) ),
'target="_blank" rel="noopener"',
'target="_blank"',
sprintf(
'<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span>',
/* translators: Hidden accessibility text. */
@ -1218,7 +1218,7 @@ class WP_Site_Health {
__( 'The SQL server is a required piece of software for the database WordPress uses to store all your site&#8217;s content and settings.' )
),
'actions' => sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
/* translators: Localized version of WordPress requirements if one exists. */
esc_url( __( 'https://wordpress.org/about/requirements/' ) ),
__( 'Learn more about what WordPress requires to run.' ),
@ -1335,7 +1335,7 @@ class WP_Site_Health {
);
$result['actions'] = sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
/* translators: Localized Support reference. */
esc_url( __( 'https://wordpress.org/support/forums/' ) ),
__( 'Get help resolving this issue.' ),
@ -1373,7 +1373,7 @@ class WP_Site_Health {
__( 'Debug mode is often enabled to gather more details about an error or site failure, but may contain sensitive information which should not be available on a publicly available website.' )
),
'actions' => sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
/* translators: Documentation explaining debugging in WordPress. */
esc_url( __( 'https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/' ) ),
__( 'Learn more about debugging in WordPress.' ),
@ -1455,7 +1455,7 @@ class WP_Site_Health {
__( 'An HTTPS connection is a more secure way of browsing the web. Many services now have HTTPS as a requirement. HTTPS allows you to take advantage of new features that can increase site speed, improve search rankings, and gain the trust of your visitors by helping to protect their online privacy.' )
),
'actions' => sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
esc_url( $default_update_url ),
__( 'Learn more about why you should use HTTPS' ),
/* translators: Hidden accessibility text. */
@ -1539,7 +1539,7 @@ class WP_Site_Health {
if ( ! empty( $direct_update_url ) ) {
$result['actions'] = sprintf(
'<p class="button-container"><a class="button button-primary" href="%1$s" target="_blank" rel="noopener">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p class="button-container"><a class="button button-primary" href="%1$s" target="_blank">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
esc_url( $direct_update_url ),
__( 'Update your site to use HTTPS' ),
/* translators: Hidden accessibility text. */
@ -1558,7 +1558,7 @@ class WP_Site_Health {
$update_url = wp_get_update_https_url();
if ( $update_url !== $default_update_url ) {
$result['description'] .= sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
esc_url( $update_url ),
__( 'Talk to your web host about supporting HTTPS for your website.' ),
/* translators: Hidden accessibility text. */
@ -2364,7 +2364,7 @@ class WP_Site_Health {
);
} else {
$result['actions'] .= sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
__( 'https://developer.wordpress.org/rest-api/frequently-asked-questions/#why-is-authentication-not-working' ),
__( 'Learn how to configure the Authorization header.' ),
/* translators: Hidden accessibility text. */
@ -2397,7 +2397,7 @@ class WP_Site_Health {
'status' => 'good',
'label' => '',
'actions' => sprintf(
'<p><a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%1$s" target="_blank" rel="noreferrer">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
__( 'https://developer.wordpress.org/advanced-administration/performance/optimization/#caching' ),
__( 'Learn more about page cache' ),
/* translators: Hidden accessibility text. */
@ -2523,7 +2523,7 @@ class WP_Site_Health {
__( 'A persistent object cache makes your site&#8217;s database more efficient, resulting in faster load times because WordPress can retrieve your site&#8217;s content and settings much more quickly.' )
),
'actions' => sprintf(
'<p><a href="%s" target="_blank" rel="noopener">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
'<p><a href="%s" target="_blank">%s<span class="screen-reader-text"> %s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a></p>',
esc_url( $action_url ),
__( 'Learn more about persistent object caching.' ),
/* translators: Hidden accessibility text. */
@ -2671,7 +2671,7 @@ class WP_Site_Health {
$result['actions'] = sprintf(
/* translators: 1: HelpHub URL, 2: Link description. */
'<p><a target="_blank" rel="noopener" href="%1$s">%2$s</a></p>',
'<p><a target="_blank" href="%1$s">%2$s</a></p>',
esc_url( __( 'https://developer.wordpress.org/advanced-administration/performance/optimization/#autoloaded-options' ) ),
__( 'More info about optimizing autoloaded options' )
);

View File

@ -1912,7 +1912,7 @@ function wp_dashboard_php_nag() {
<p class="button-container">
<?php
printf(
'<a class="button button-primary" href="%1$s" target="_blank" rel="noopener">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
'<a class="button button-primary" href="%1$s" target="_blank">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
esc_url( wp_get_update_php_url() ),
__( 'Learn more about updating PHP' ),
/* translators: Hidden accessibility text. */

View File

@ -3243,7 +3243,7 @@ function edit_form_image_editor( $post ) {
__( '<a href="%1$s" %2$s>Learn how to describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ),
/* translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations. */
esc_url( __( 'https://www.w3.org/WAI/tutorials/images/decision-tree/' ) ),
'target="_blank" rel="noopener"',
'target="_blank"',
sprintf(
'<span class="screen-reader-text"> %s</span>',
/* translators: Hidden accessibility text. */

View File

@ -215,11 +215,7 @@ class Walker_Nav_Menu extends Walker {
$atts = array();
$atts['title'] = ! empty( $menu_item->attr_title ) ? $menu_item->attr_title : '';
$atts['target'] = ! empty( $menu_item->target ) ? $menu_item->target : '';
if ( '_blank' === $menu_item->target && empty( $menu_item->xfn ) ) {
$atts['rel'] = 'noopener';
} else {
$atts['rel'] = $menu_item->xfn;
}
$atts['rel'] = ! empty( $menu_item->xfn ) ? $menu_item->xfn : '';
if ( ! empty( $menu_item->url ) ) {
if ( get_privacy_policy_url() === $menu_item->url ) {

View File

@ -3766,7 +3766,7 @@ function wp_comments_personal_data_exporter( $email_address, $page = 1 ) {
case 'comment_link':
$value = get_comment_link( $comment->comment_ID );
$value = sprintf(
'<a href="%s" target="_blank" rel="noopener">%s</a>',
'<a href="%s" target="_blank">%s</a>',
esc_url( $value ),
esc_html( $value )
);

View File

@ -153,9 +153,6 @@ foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pr
add_filter( $filter, 'balanceTags', 50 );
}
// Add proper rel values for links with target.
add_action( 'init', 'wp_init_targeted_link_rel_filters' );
// Format strings for display.
foreach ( array( 'comment_author', 'term_name', 'link_name', 'link_description', 'link_notes', 'bloginfo', 'wp_title', 'document_title', 'widget_title' ) as $filter ) {
add_filter( $filter, 'wptexturize' );

View File

@ -3294,11 +3294,14 @@ function wp_rel_ugc( $text ) {
*
* @since 5.1.0
* @since 5.6.0 Removed 'noreferrer' relationship.
* @deprecated 6.7.0
*
* @param string $text Content that may contain HTML A elements.
* @return string Converted content.
*/
function wp_targeted_link_rel( $text ) {
_deprecated_function( __FUNCTION__, '6.7.0' );
// Don't run (more expensive) regex if no links with targets.
if ( stripos( $text, 'target' ) === false || stripos( $text, '<a ' ) === false || is_serialized( $text ) ) {
return $text;
@ -3332,11 +3335,14 @@ function wp_targeted_link_rel( $text ) {
*
* @since 5.1.0
* @since 5.6.0 Removed 'noreferrer' relationship.
* @deprecated 6.7.0
*
* @param array $matches Single match.
* @return string HTML A Element with `rel="noopener"` in addition to any existing values.
*/
function wp_targeted_link_rel_callback( $matches ) {
_deprecated_function( __FUNCTION__, '6.7.0' );
$link_html = $matches[1];
$original_link_html = $link_html;
@ -3383,46 +3389,20 @@ function wp_targeted_link_rel_callback( $matches ) {
* Adds all filters modifying the rel attribute of targeted links.
*
* @since 5.1.0
* @deprecated 6.7.0
*/
function wp_init_targeted_link_rel_filters() {
$filters = array(
'title_save_pre',
'content_save_pre',
'excerpt_save_pre',
'content_filtered_save_pre',
'pre_comment_content',
'pre_term_description',
'pre_link_description',
'pre_link_notes',
'pre_user_description',
);
foreach ( $filters as $filter ) {
add_filter( $filter, 'wp_targeted_link_rel' );
}
_deprecated_function( __FUNCTION__, '6.7.0' );
}
/**
* Removes all filters modifying the rel attribute of targeted links.
*
* @since 5.1.0
* @deprecated 6.7.0
*/
function wp_remove_targeted_link_rel_filters() {
$filters = array(
'title_save_pre',
'content_save_pre',
'excerpt_save_pre',
'content_filtered_save_pre',
'pre_comment_content',
'pre_term_description',
'pre_link_description',
'pre_link_notes',
'pre_user_description',
);
foreach ( $filters as $filter ) {
remove_filter( $filter, 'wp_targeted_link_rel' );
}
_deprecated_function( __FUNCTION__, '6.7.0' );
}
/**

View File

@ -8517,7 +8517,7 @@ function wp_direct_php_update_button() {
echo '<p class="button-container">';
printf(
'<a class="button button-primary" href="%1$s" target="_blank" rel="noopener">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
'<a class="button button-primary" href="%1$s" target="_blank">%2$s<span class="screen-reader-text"> %3$s</span><span aria-hidden="true" class="dashicons dashicons-external"></span></a>',
esc_url( $direct_update_url ),
__( 'Update PHP' ),
/* translators: Hidden accessibility text. */

View File

@ -4,7 +4,7 @@
renderHtml: function() {
return (
'<div id="' + this._id + '" class="wp-link-preview">' +
'<a href="' + this.url + '" target="_blank" rel="noopener" tabindex="-1">' + this.url + '</a>' +
'<a href="' + this.url + '" target="_blank" tabindex="-1">' + this.url + '</a>' +
'</div>'
);
},

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -323,7 +323,7 @@
var html = '<a href="' + attrs.href + '"';
if ( attrs.target ) {
html += ' rel="noopener" target="' + attrs.target + '"';
html += ' target="' + attrs.target + '"';
}
return html + '>';

File diff suppressed because one or more lines are too long

View File

@ -161,7 +161,7 @@ function wp_print_media_templates() {
__( '<a href="%1$s" %2$s>Learn how to describe the purpose of the image%3$s</a>. Leave empty if the image is purely decorative.' ),
/* translators: Localized tutorial, if one exists. W3C Web Accessibility Initiative link has list of existing translations. */
esc_url( __( 'https://www.w3.org/WAI/tutorials/images/decision-tree/' ) ),
'target="_blank" rel="noopener"',
'target="_blank"',
sprintf(
'<span class="screen-reader-text"> %s</span>',
/* translators: Hidden accessibility text. */

View File

@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
$wp_version = '6.7-alpha-59119';
$wp_version = '6.7-alpha-59120';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.

View File

@ -149,9 +149,6 @@ class WP_Widget_Custom_HTML extends WP_Widget {
/** This filter is documented in wp-includes/widgets/class-wp-widget-text.php */
$content = apply_filters( 'widget_text', $instance['content'], $simulated_text_widget_instance, $this );
// Adds 'noopener' relationship, without duplicating values, to all HTML A elements that have a target.
$content = wp_targeted_link_rel( $content );
/**
* Filters the content of the Custom HTML widget.
*

View File

@ -288,7 +288,7 @@ class WP_Widget_Media_Image extends WP_Widget_Media {
$link .= '>';
$link .= $image;
$link .= '</a>';
$image = wp_targeted_link_rel( $link );
$image = $link;
}
if ( $caption ) {

View File

@ -334,9 +334,6 @@ class WP_Widget_Text extends WP_Widget {
$text = preg_replace_callback( '#<(video|iframe|object|embed)\s[^>]*>#i', array( $this, 'inject_video_max_width_style' ), $text );
// Adds 'noopener' relationship, without duplicating values, to all HTML A elements that have a target.
$text = wp_targeted_link_rel( $text );
?>
<div class="textwidget"><?php echo $text; ?></div>
<?php

View File

@ -697,7 +697,7 @@ switch ( $action ) {
);
printf(
'<a href="%s" rel="noopener" target="_blank">%s%s</a>',
'<a href="%s" target="_blank">%s%s</a>',
esc_url( $admin_email_help_url ),
__( 'Why is this important?' ),
$accessibility_text
@ -1629,7 +1629,6 @@ switch ( $action ) {
for ( i in links ) {
if ( links[i].href ) {
links[i].target = '_blank';
links[i].rel = 'noopener';
}
}
} catch( er ) {}