Skip to content

Commit 1b57f98

Browse files
committed
Security: Enable the referrer policy header on the login screen.
This sets the same referrer policy of `strict-origin-when-cross-origin` that's used in the admin area to prevent a referrer being sent to other origins. This helps prevent unwanted exposure of potentially sensitive information that may be contained within the URL. The header can be disabled if necessary by removing the `wp_admin_headers` action from the `login_init` hook. Props kkmuffme, sagarlakhani, albatross10 Fixes #62273 See #42036 git-svn-id: https://develop.svn.wordpress.org/trunk@59712 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 482d3e1 commit 1b57f98

File tree

4 files changed

+25
-24
lines changed

4 files changed

+25
-24
lines changed

src/wp-admin/includes/admin-filters.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444

4545
// Misc hooks.
4646
add_action( 'admin_init', 'wp_admin_headers' );
47-
add_action( 'login_init', 'wp_admin_headers' );
4847
add_action( 'admin_init', 'send_frame_options_header', 10, 0 );
4948
add_action( 'admin_head', 'wp_admin_canonical_url' );
5049
add_action( 'admin_head', 'wp_site_icon' );

src/wp-admin/includes/misc.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,29 +1415,6 @@ function wp_admin_canonical_url() {
14151415
<?php
14161416
}
14171417

1418-
/**
1419-
* Sends a referrer policy header so referrers are not sent externally from administration screens.
1420-
*
1421-
* @since 4.9.0
1422-
*/
1423-
function wp_admin_headers() {
1424-
$policy = 'strict-origin-when-cross-origin';
1425-
1426-
/**
1427-
* Filters the admin referrer policy header value.
1428-
*
1429-
* @since 4.9.0
1430-
* @since 4.9.5 The default value was changed to 'strict-origin-when-cross-origin'.
1431-
*
1432-
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
1433-
*
1434-
* @param string $policy The admin referrer policy header value. Default 'strict-origin-when-cross-origin'.
1435-
*/
1436-
$policy = apply_filters( 'admin_referrer_policy', $policy );
1437-
1438-
header( sprintf( 'Referrer-Policy: %s', $policy ) );
1439-
}
1440-
14411418
/**
14421419
* Outputs JS that reloads the page if the user navigated to it with the Back or Forward button.
14431420
*

src/wp-includes/default-filters.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@
389389
add_action( 'login_head', 'wp_site_icon', 99 );
390390
add_action( 'login_footer', 'wp_print_footer_scripts', 20 );
391391
add_action( 'login_init', 'send_frame_options_header', 10, 0 );
392+
add_action( 'login_init', 'wp_admin_headers' );
392393

393394
// Feed generator tags.
394395
foreach ( array( 'rss2_head', 'commentsrss2_head', 'rss_head', 'rdf_header', 'atom_head', 'comments_atom_head', 'opml_head', 'app_head' ) as $action ) {

src/wp-includes/functions.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7144,6 +7144,30 @@ function send_frame_options_header() {
71447144
header( 'X-Frame-Options: SAMEORIGIN' );
71457145
}
71467146

7147+
/**
7148+
* Sends a referrer policy header so referrers are not sent externally from administration screens.
7149+
*
7150+
* @since 4.9.0
7151+
* @since 6.8.0 This function was moved from `wp-admin/includes/misc.php` to `wp-includes/functions.php`.
7152+
*/
7153+
function wp_admin_headers() {
7154+
$policy = 'strict-origin-when-cross-origin';
7155+
7156+
/**
7157+
* Filters the admin referrer policy header value.
7158+
*
7159+
* @since 4.9.0
7160+
* @since 4.9.5 The default value was changed to 'strict-origin-when-cross-origin'.
7161+
*
7162+
* @link https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy
7163+
*
7164+
* @param string $policy The admin referrer policy header value. Default 'strict-origin-when-cross-origin'.
7165+
*/
7166+
$policy = apply_filters( 'admin_referrer_policy', $policy );
7167+
7168+
header( sprintf( 'Referrer-Policy: %s', $policy ) );
7169+
}
7170+
71477171
/**
71487172
* Retrieves a list of protocols to allow in HTML attributes.
71497173
*

0 commit comments

Comments
 (0)