Make WordPress Core

Ticket #63188: 63188.patch

File 63188.patch, 4.1 KB (added by viralsampat, 11 months ago)

I have checked above mentioned issue and founds few files. Here, I have added its patch.

  • src/wp-includes/class-wp-application-passwords.php

    diff --git src/wp-includes/class-wp-application-passwords.php src/wp-includes/class-wp-application-passwords.php
    index 8ed02dd6f3..af4103529c 100644
    class WP_Application_Passwords { 
    347347                        }
    348348
    349349                        $password['last_used'] = time();
    350                         $password['last_ip']   = $_SERVER['REMOTE_ADDR'];
     350
     351                        // Get remote IP address.
     352                        $remote_addr = filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP );
     353
     354                        $password['last_ip']   = isset( $remote_addr ) ? $remote_addr : null;
    351355
    352356                        $saved = static::set_user_application_passwords( $user_id, $passwords );
    353357
  • src/wp-includes/class-wp-session-tokens.php

    diff --git src/wp-includes/class-wp-session-tokens.php src/wp-includes/class-wp-session-tokens.php
    index 9482e1b948..b5eb90ed49 100644
    abstract class WP_Session_Tokens { 
    129129                $session               = apply_filters( 'attach_session_information', array(), $this->user_id );
    130130                $session['expiration'] = $expiration;
    131131
     132                // Get the IP address and user-agent.
     133                $remore_addr = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
     134
    132135                // IP address.
    133                 if ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) {
    134                         $session['ip'] = $_SERVER['REMOTE_ADDR'];
     136                if ( ! empty( $remore_addr ) ) {
     137                        $session['ip'] = $remore_addr;
    135138                }
    136139
    137140                // User-agent.
  • src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    diff --git src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
    index a0b68759f9..592a4f21ad 100644
    class WP_REST_Comments_Controller extends WP_REST_Controller { 
    495495                }
    496496
    497497                if ( isset( $request['author_ip'] ) && ! current_user_can( 'moderate_comments' ) ) {
    498                         if ( empty( $_SERVER['REMOTE_ADDR'] ) || $request['author_ip'] !== $_SERVER['REMOTE_ADDR'] ) {
     498                       
     499                        // Get remote IP address.
     500                        $remote_addr = filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP );
     501
     502                        if ( empty( $remote_addr ) || $request['author_ip'] !== $remote_addr ) {
    499503                                return new WP_Error(
    500504                                        'rest_comment_invalid_author_ip',
    501505                                        /* translators: %s: Request parameter. */
    class WP_REST_Comments_Controller extends WP_REST_Controller { 
    13001304        protected function prepare_item_for_database( $request ) {
    13011305                $prepared_comment = array();
    13021306
     1307                // Get remote IP address.
     1308                $remote_addr = filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP );
     1309
    13031310                /*
    13041311                 * Allow the comment_content to be set via the 'content' or
    13051312                 * the 'content.raw' properties of the Request object.
    class WP_REST_Comments_Controller extends WP_REST_Controller { 
    13491356
    13501357                if ( isset( $request['author_ip'] ) && current_user_can( 'moderate_comments' ) ) {
    13511358                        $prepared_comment['comment_author_IP'] = $request['author_ip'];
    1352                 } elseif ( ! empty( $_SERVER['REMOTE_ADDR'] ) && rest_is_ip_address( $_SERVER['REMOTE_ADDR'] ) ) {
    1353                         $prepared_comment['comment_author_IP'] = $_SERVER['REMOTE_ADDR'];
     1359                } elseif ( ! empty( $remote_addr ) && rest_is_ip_address( $remote_addr ) ) {
     1360                        $prepared_comment['comment_author_IP'] = $remote_addr;
    13541361                } else {
    13551362                        $prepared_comment['comment_author_IP'] = '127.0.0.1';
    13561363                }
  • src/wp-includes/user.php

    diff --git src/wp-includes/user.php src/wp-includes/user.php
    index 8d4aab98c1..77c1344094 100644
    function retrieve_password( $user_login = '' ) { 
    33033303        $message .= network_site_url( 'wp-login.php?login=' . rawurlencode( $user_login ) . "&key=$key&action=rp", 'login' ) . '&wp_lang=' . $locale . "\r\n\r\n";
    33043304
    33053305        if ( ! is_user_logged_in() ) {
    3306                 $requester_ip = $_SERVER['REMOTE_ADDR'];
     3306                // Get remote address.
     3307                $remote_addr = filter_input(INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP);
     3308               
     3309                $requester_ip = isset( $remote_addr ) ? $remote_addr : '';
    33073310                if ( $requester_ip ) {
    33083311                        $message .= sprintf(
    33093312                                /* translators: %s: IP address of password reset requester. */