Skip to content

Commit da3921b

Browse files
committed
Security: Backport the WordPress 7.0.3 security fixes to the 6.5 branch.
- Users: Ensure a proper email address is used before sending email confirmations. - Formatting: Prevent stack overflow in `safecss_filter_attr`. - Multisite: Enforce the active signup policy for existing users. - HTTP API: Improve compliance with IPv4 Special-Purpose Address Space. - Users: Prevent Usernames from mangling HTML - Canonical: Only redirect for publicly viewable post types. - Administration: When `wp_is_large_user_count()`, ensure that the post author is always added to author dropdown. - Editor: Fix output of Post Date. Merges [63060],[63061],[63062],[63063],[63064],[63065],[63067] to the 6.5 branch. Props xknown, westonruter, jeremyfelt, peterwilsoncc, paulkevan, lucasbustamante, jorbin, desrosj, vortfu, dmsnell, johnbillion, ehtis, batmoo, lancewillett, jonsurrell, isabel_brison, bernhard-reiter, tyxla, aduth. git-svn-id: https://develop.svn.wordpress.org/branches/6.5@63081 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c910d25 commit da3921b

11 files changed

Lines changed: 153 additions & 28 deletions

File tree

‎package-lock.json‎

Lines changed: 80 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
"@wordpress/blob": "3.51.1",
8686
"@wordpress/block-directory": "4.28.12",
8787
"@wordpress/block-editor": "12.19.9",
88-
"@wordpress/block-library": "8.28.12",
88+
"@wordpress/block-library": "8.28.13",
8989
"@wordpress/block-serialization-default-parser": "4.51.1",
9090
"@wordpress/blocks": "12.28.6",
9191
"@wordpress/commands": "0.22.6",

‎src/js/_enqueues/admin/inline-edit-post.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,12 @@ window.wp = window.wp || {};
346346
if ( !$(':input[name="post_author"] option[value="' + $('.post_author', rowData).text() + '"]', editRow).val() ) {
347347

348348
// The post author no longer has edit capabilities, so we need to add them to the list of authors.
349-
$(':input[name="post_author"]', editRow).prepend('<option value="' + $('.post_author', rowData).text() + '">' + $('#post-' + id + ' .author').text() + '</option>');
349+
$(':input[name="post_author"]', editRow).prepend(
350+
new Option(
351+
$('#post-' + id + ' .author').text(),
352+
$('.post_author', rowData).text()
353+
)
354+
);
350355
}
351356
if ( $( ':input[name="post_author"] option', editRow ).length === 1 ) {
352357
$('label.inline-edit-author', editRow).hide();

‎src/wp-admin/includes/user.php‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ function edit_user( $user_id = 0 ) {
4444
$user->user_login = sanitize_user( wp_unslash( $_POST['user_login'] ), true );
4545
}
4646

47+
$errors = new WP_Error();
48+
4749
$pass1 = '';
4850
$pass2 = '';
4951
if ( isset( $_POST['pass1'] ) ) {
@@ -78,7 +80,12 @@ function edit_user( $user_id = 0 ) {
7880
}
7981

8082
if ( isset( $_POST['email'] ) ) {
81-
$user->user_email = sanitize_text_field( wp_unslash( $_POST['email'] ) );
83+
$maybe_email = wp_unslash( $_POST['email'] );
84+
if ( is_string( $maybe_email ) && is_email( $maybe_email ) ) {
85+
$user->user_email = $maybe_email;
86+
} else {
87+
$errors->add( 'invalid_email', __( '<strong>Error:</strong> The email address is not correct.' ), array( 'form-field' => 'email' ) );
88+
}
8289
}
8390
if ( isset( $_POST['url'] ) ) {
8491
if ( empty( $_POST['url'] ) || 'http://' === $_POST['url'] ) {
@@ -145,8 +152,6 @@ function edit_user( $user_id = 0 ) {
145152
$user->use_ssl = 1;
146153
}
147154

148-
$errors = new WP_Error();
149-
150155
/* checking that username has been typed */
151156
if ( '' === $user->user_login ) {
152157
$errors->add( 'user_login', __( '<strong>Error:</strong> Please enter a username.' ) );

‎src/wp-includes/blocks/post-date.php‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ function render_block_core_post_date( $attributes, $content, $block ) {
4747
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classes ) ) );
4848

4949
if ( isset( $attributes['isLink'] ) && $attributes['isLink'] ) {
50-
$formatted_date = sprintf( '<a href="%1s">%2s</a>', get_the_permalink( $post_ID ), $formatted_date );
50+
$formatted_date = sprintf( '<a href="%1$s">%2$s</a>', esc_url( get_the_permalink( $post_ID ) ), esc_html( $formatted_date ) );
51+
} else {
52+
$formatted_date = esc_html( $formatted_date );
5153
}
5254

5355
return sprintf(

‎src/wp-includes/canonical.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ function redirect_guess_404_permalink() {
976976
if ( empty( $post_types ) ) {
977977
return false;
978978
}
979-
$where .= " AND post_type IN ('" . join( "', '", esc_sql( get_query_var( 'post_type' ) ) ) . "')";
979+
$where .= " AND post_type IN ('" . join( "', '", esc_sql( $post_types ) ) . "')";
980980
} else {
981981
if ( ! in_array( get_query_var( 'post_type' ), $publicly_viewable_post_types, true ) ) {
982982
return false;

‎src/wp-includes/http.php‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -565,9 +565,30 @@ function wp_http_validate_url( $url ) {
565565
}
566566
if ( $ip ) {
567567
$parts = array_map( 'intval', explode( '.', $ip ) );
568-
if ( 127 === $parts[0] || 10 === $parts[0] || 0 === $parts[0]
569-
|| ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
570-
|| ( 192 === $parts[0] && 168 === $parts[1] )
568+
569+
/*
570+
* These IP address ranges are not considered valid external hosts for HTTP requests.
571+
*
572+
* If the host resolves to an IP address in these ranges, the request will be rejected unless the 'http_request_host_is_external' filter allows it.
573+
*
574+
* References:
575+
*
576+
* - IPv4 Special-Purpose Address Space: https://www.iana.org/assignments/iana-ipv4-special-registry/iana-ipv4-special-registry.xhtml
577+
* - IPv4 Multicast Address Assignments: https://www.rfc-editor.org/rfc/rfc5771.html
578+
*/
579+
if ( 127 === $parts[0] || 10 === $parts[0] || 0 === $parts[0] // 127.0.0.0/8 (loopback), 10.0.0.0/8 (private), 0.0.0.0/8 (this network).
580+
|| ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] ) // 172.16.0.0/12 (private).
581+
|| ( 192 === $parts[0] && 168 === $parts[1] ) // 192.168.0.0/16 (private).
582+
|| ( 192 === $parts[0] && 0 === $parts[1] && 0 === $parts[2] ) // 192.0.0.0/24 (IETF protocol assignments).
583+
|| ( 192 === $parts[0] && 0 === $parts[1] && 2 === $parts[2] ) // 192.0.2.0/24 (TEST-NET-1).
584+
|| ( 192 === $parts[0] && 88 === $parts[1] && 99 === $parts[2] ) // 192.88.99.0/24 (6to4 relay anycast).
585+
|| ( 198 === $parts[0] && 51 === $parts[1] && 100 === $parts[2] ) // 198.51.100.0/24 (TEST-NET-2).
586+
|| ( 203 === $parts[0] && 0 === $parts[1] && 113 === $parts[2] ) // 203.0.113.0/24 (TEST-NET-3).
587+
|| ( 169 === $parts[0] && 254 === $parts[1] ) // 169.254.0.0/16 (link-local and cloud metadata).
588+
|| ( 100 === $parts[0] && 64 <= $parts[1] && 127 >= $parts[1] ) // 100.64.0.0/10 (CGNAT).
589+
|| ( 198 === $parts[0] && 18 <= $parts[1] && 19 >= $parts[1] ) // 198.18.0.0/15 (benchmarking).
590+
|| ( 224 <= $parts[0] && 239 >= $parts[0] ) // 224.0.0.0/4 (multicast).
591+
|| 240 <= $parts[0] // 240.0.0.0/4 (reserved, includes 255.255.255.255 broadcast).
571592
) {
572593
// If host appears local, reject unless specifically allowed.
573594
/**

‎src/wp-includes/kses.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2595,11 +2595,16 @@ function safecss_filter_attr( $css, $deprecated = '' ) {
25952595
$css_test_string
25962596
);
25972597

2598+
// Bail if the recursive function stripping hit a PCRE error (e.g. stack/backtrack limit).
2599+
if ( null === $css_test_string ) {
2600+
continue;
2601+
}
2602+
25982603
/*
25992604
* Disallow CSS containing \ ( & } = or comments, except for within url(), var(), calc(), etc.
26002605
* which were removed from the test string above.
26012606
*/
2602-
$allow_css = ! preg_match( '%[\\\(&=}]|/\*%', $css_test_string );
2607+
$allow_css = 0 === preg_match( '%[\\\(&=}]|/\*%', $css_test_string );
26032608

26042609
/**
26052610
* Filters the check for unsafe CSS in `safecss_filter_attr`.

‎src/wp-includes/user.php‎

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function wp_authenticate_username_password( $user, $username, $password ) {
163163
sprintf(
164164
/* translators: %s: User name. */
165165
__( '<strong>Error:</strong> The username <strong>%s</strong> is not registered on this site. If you are unsure of your username, try your email address instead.' ),
166-
$username
166+
esc_html( $username )
167167
)
168168
);
169169
}
@@ -188,7 +188,7 @@ function wp_authenticate_username_password( $user, $username, $password ) {
188188
sprintf(
189189
/* translators: %s: User name. */
190190
__( '<strong>Error:</strong> The password you entered for the username %s is incorrect.' ),
191-
'<strong>' . $username . '</strong>'
191+
'<strong>' . esc_html( $username ) . '</strong>'
192192
) .
193193
' <a href="' . wp_lostpassword_url() . '">' .
194194
__( 'Lost your password?' ) .
@@ -260,7 +260,7 @@ function wp_authenticate_email_password( $user, $email, $password ) {
260260
sprintf(
261261
/* translators: %s: Email address. */
262262
__( '<strong>Error:</strong> The password you entered for the email address %s is incorrect.' ),
263-
'<strong>' . $email . '</strong>'
263+
'<strong>' . esc_html( $email ) . '</strong>'
264264
) .
265265
' <a href="' . wp_lostpassword_url() . '">' .
266266
__( 'Lost your password?' ) .
@@ -3374,7 +3374,7 @@ function register_new_user( $user_login, $user_email ) {
33743374
sprintf(
33753375
/* translators: %s: Link to the login page. */
33763376
__( '<strong>Error:</strong> This email address is already registered. <a href="%s">Log in</a> with this address or choose another one.' ),
3377-
wp_login_url()
3377+
esc_url( wp_login_url() )
33783378
)
33793379
);
33803380
}
@@ -3422,7 +3422,7 @@ function register_new_user( $user_login, $user_email ) {
34223422
sprintf(
34233423
/* translators: %s: Admin email address. */
34243424
__( '<strong>Error:</strong> Could not register you&hellip; please contact the <a href="mailto:%s">site admin</a>!' ),
3425-
get_option( 'admin_email' )
3425+
esc_attr( get_option( 'admin_email' ) )
34263426
)
34273427
);
34283428
return $errors;
@@ -3645,18 +3645,26 @@ function _wp_get_current_user() {
36453645
*
36463646
* @since 3.0.0
36473647
* @since 4.9.0 This function was moved from wp-admin/includes/ms.php so it's no longer Multisite specific.
3648+
* @since 7.0.3 Added the `$user_id` parameter, which is sent with the `personal_options_update` action.
3649+
*
3650+
* @param int $user_id Optional. The ID of the user whose email is being changed. Defaults to `$_POST['user_id']` if set, otherwise 0.
36483651
*
36493652
* @global WP_Error $errors WP_Error object.
36503653
*/
3651-
function send_confirmation_on_profile_email() {
3654+
function send_confirmation_on_profile_email( $user_id = 0 ) {
36523655
global $errors;
36533656

3657+
// Maintain backward compatibility for those relying on a check based on $_POST['user_id'].
3658+
if ( ! $user_id && isset( $_POST['user_id'] ) ) {
3659+
$user_id = (int) $_POST['user_id'];
3660+
}
3661+
36543662
$current_user = wp_get_current_user();
36553663
if ( ! is_object( $errors ) ) {
36563664
$errors = new WP_Error();
36573665
}
36583666

3659-
if ( $current_user->ID != $_POST['user_id'] ) {
3667+
if ( 0 === $current_user->ID || $current_user->ID !== (int) $user_id ) {
36603668
return false;
36613669
}
36623670

@@ -3670,6 +3678,7 @@ function send_confirmation_on_profile_email() {
36703678
)
36713679
);
36723680

3681+
$_POST['email'] = addslashes( $current_user->user_email );
36733682
return;
36743683
}
36753684

@@ -3683,6 +3692,7 @@ function send_confirmation_on_profile_email() {
36833692
);
36843693
delete_user_meta( $current_user->ID, '_new_email' );
36853694

3695+
$_POST['email'] = addslashes( $current_user->user_email );
36863696
return;
36873697
}
36883698

‎src/wp-login.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,7 +1209,7 @@ function wp_login_viewport_meta() {
12091209
sprintf(
12101210
/* translators: %s: Link to the login page. */
12111211
__( 'Check your email for the confirmation link, then visit the <a href="%s">login page</a>.' ),
1212-
wp_login_url()
1212+
esc_url( wp_login_url() )
12131213
),
12141214
'message'
12151215
);
@@ -1219,7 +1219,7 @@ function wp_login_viewport_meta() {
12191219
sprintf(
12201220
/* translators: %s: Link to the login page. */
12211221
__( 'Registration complete. Please check your email, then visit the <a href="%s">login page</a>.' ),
1222-
wp_login_url()
1222+
esc_url( wp_login_url() )
12231223
),
12241224
'message'
12251225
);

0 commit comments

Comments
 (0)