Make WordPress Core

Changeset 46496 for branches/4.6


Ignore:
Timestamp:
10/14/2019 07:01:10 PM (7 years ago)
Author:
whyisjake
Message:

Backporting several bug fixes.

  • Query: Remove the static query property.
  • HTTP API: Protect against hex interpretation.
  • Filesystem API: Prevent directory travelersals when creating new folders.
  • Administration: Ensure that admin referer nonce is valid.
  • REST API: Send a Vary: Origin header on GET requests.

Backports [46474], [46475], [46476], [46477], [46478], [46483], [46485] to the 4.6 branch.

Location:
branches/4.6
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/4.6

  • branches/4.6/src/wp-includes/class-wp.php

    r44057 r46496  
    1616         * @var array
    1717         */
    18         public $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type', 'embed' );
     18        public $public_query_vars = array( 'm', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'pagename', 'page_id', 'error', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type', 'embed' );
    1919
    2020        /**
  • branches/4.6/src/wp-includes/functions.php

    r43992 r46496  
    16111611        if ( file_exists( $target ) )
    16121612                return @is_dir( $target );
     1613
     1614        // Do not allow path traversals.
     1615        if ( false !== strpos( $target, '../' ) || false !== strpos( $target, '..' . DIRECTORY_SEPARATOR ) ) {
     1616                return false;
     1617        }
    16131618
    16141619        // We need to find the permissions of the parent folder that exists and inherit that.
  • branches/4.6/src/wp-includes/http.php

    r42911 r46496  
    539539                } else {
    540540                        $ip = gethostbyname( $host );
    541                         if ( $ip === $host ) // Error condition for gethostbyname()
    542                                 $ip = false;
     541                        if ( $ip === $host ) { // Error condition for gethostbyname()
     542                                return false;
     543                        }
    543544                }
    544545                if ( $ip ) {
  • branches/4.6/src/wp-includes/pluggable.php

    r45978 r46496  
    10391039 */
    10401040function check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) {
    1041         if ( -1 == $action )
     1041        if ( -1 === $action )
    10421042                _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2.0' );
    10431043
     
    10571057        do_action( 'check_admin_referer', $action, $result );
    10581058
    1059         if ( ! $result && ! ( -1 == $action && strpos( $referer, $adminurl ) === 0 ) ) {
     1059        if ( ! $result && ! ( -1 === $action && strpos( $referer, $adminurl ) === 0 ) ) {
    10601060                wp_nonce_ays( $action );
    10611061                die();
     
    10821082 */
    10831083function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) {
     1084        if ( -1 === $action )
     1085                _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2.0' );
     1086
    10841087        $nonce = '';
    10851088
     
    24602463}
    24612464endif;
    2462 
  • branches/4.6/src/wp-includes/query.php

    r39955 r46496  
    14171417                        , 'attachment_id'
    14181418                        , 'name'
    1419                         , 'static'
    14201419                        , 'pagename'
    14211420                        , 'page_id'
     
    16381637                        // post is being queried.
    16391638                        $this->is_single = true;
    1640                 } elseif ( '' != $qv['static'] || '' != $qv['pagename'] || !empty($qv['page_id']) ) {
     1639                } elseif ( '' != $qv['pagename'] || !empty($qv['page_id']) ) {
    16411640                        $this->is_page = true;
    16421641                        $this->is_single = false;
  • branches/4.6/src/wp-includes/rest-api.php

    r37905 r46496  
    396396                header( 'Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE' );
    397397                header( 'Access-Control-Allow-Credentials: true' );
     398                header( 'Vary: Origin', false );
     399        } elseif ( ! headers_sent() && 'GET' === $_SERVER['REQUEST_METHOD'] && ! is_user_logged_in() ) {
     400                header( 'Vary: Origin', false );
    398401        }
    399402
  • branches/4.6/src/wp-includes/theme.php

    r37985 r46496  
    13751375
    13761376        if ( $background ) {
    1377                 $image = " background-image: url('$background');";
     1377                $image = " background-image: url('" . esc_url_raw( $background ) . "');";
    13781378
    13791379                $repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) );
  • branches/4.6/tests/phpunit/tests/auth.php

    r36617 r46496  
    154154        }
    155155
     156        /**
     157         * @ticket 36361
     158         */
     159        public function test_check_admin_referer_with_no_action_triggers_doing_it_wrong() {
     160                $this->setExpectedIncorrectUsage( 'check_admin_referer' );
     161
     162                // A valid nonce needs to be set so the check doesn't die()
     163                $_REQUEST['_wpnonce'] = wp_create_nonce( -1 );
     164                $result = check_admin_referer();
     165                $this->assertSame( 1, $result );
     166
     167                unset( $_REQUEST['_wpnonce'] );
     168        }
     169
     170        public function test_check_admin_referer_with_default_action_as_string_not_doing_it_wrong() {
     171                // A valid nonce needs to be set so the check doesn't die()
     172                $_REQUEST['_wpnonce'] = wp_create_nonce( '-1' );
     173                $result               = check_admin_referer( '-1' );
     174                $this->assertSame( 1, $result );
     175
     176                unset( $_REQUEST['_wpnonce'] );
     177        }
     178
     179        /**
     180         * @ticket 36361
     181         */
     182        public function test_check_ajax_referer_with_no_action_triggers_doing_it_wrong() {
     183                $this->setExpectedIncorrectUsage( 'check_ajax_referer' );
     184
     185                // A valid nonce needs to be set so the check doesn't die()
     186                $_REQUEST['_wpnonce'] = wp_create_nonce( -1 );
     187                $result = check_ajax_referer();
     188                $this->assertSame( 1, $result );
     189
     190                unset( $_REQUEST['_wpnonce'] );
     191        }
     192
    156193        function test_password_length_limit() {
    157194                $limit = str_repeat( 'a', 4096 );
  • branches/4.6/tests/phpunit/tests/query/vars.php

    r36048 r46496  
    1717                do_action( 'init' );
    1818
    19                 $this->assertEquals( array(
     19                $this->assertEquals(
     20                        array(
    2021
    21                         // Static public query vars:
    22                         'm',
    23                         'p',
    24                         'posts',
    25                         'w',
    26                         'cat',
    27                         'withcomments',
    28                         'withoutcomments',
    29                         's',
    30                         'search',
    31                         'exact',
    32                         'sentence',
    33                         'calendar',
    34                         'page',
    35                         'paged',
    36                         'more',
    37                         'tb',
    38                         'pb',
    39                         'author',
    40                         'order',
    41                         'orderby',
    42                         'year',
    43                         'monthnum',
    44                         'day',
    45                         'hour',
    46                         'minute',
    47                         'second',
    48                         'name',
    49                         'category_name',
    50                         'tag',
    51                         'feed',
    52                         'author_name',
    53                         'static',
    54                         'pagename',
    55                         'page_id',
    56                         'error',
    57                         'attachment',
    58                         'attachment_id',
    59                         'subpost',
    60                         'subpost_id',
    61                         'preview',
    62                         'robots',
    63                         'taxonomy',
    64                         'term',
    65                         'cpage',
    66                         'post_type',
    67                         'embed',
     22                                // Static public query vars:
     23                                'm',
     24                                'p',
     25                                'posts',
     26                                'w',
     27                                'cat',
     28                                'withcomments',
     29                                'withoutcomments',
     30                                's',
     31                                'search',
     32                                'exact',
     33                                'sentence',
     34                                'calendar',
     35                                'page',
     36                                'paged',
     37                                'more',
     38                                'tb',
     39                                'pb',
     40                                'author',
     41                                'order',
     42                                'orderby',
     43                                'year',
     44                                'monthnum',
     45                                'day',
     46                                'hour',
     47                                'minute',
     48                                'second',
     49                                'name',
     50                                'category_name',
     51                                'tag',
     52                                'feed',
     53                                'author_name',
     54                                'pagename',
     55                                'page_id',
     56                                'error',
     57                                'attachment',
     58                                'attachment_id',
     59                                'subpost',
     60                                'subpost_id',
     61                                'preview',
     62                                'robots',
     63                                'taxonomy',
     64                                'term',
     65                                'cpage',
     66                                'post_type',
     67                                'embed',
    6868
    69                         // Dynamically added public query vars:
    70                         'post_format',
    71                         'rest_route',
     69                                // Dynamically added public query vars:
     70                                'post_format',
     71                                'rest_route',
    7272
    73                 ), $wp->public_query_vars, 'Care should be taken when introducing new public query vars. See https://core.trac.wordpress.org/ticket/35115' );
     73                        ),
     74                        $wp->public_query_vars,
     75                        'Care should be taken when introducing new public query vars. See https://core.trac.wordpress.org/ticket/35115'
     76                );
    7477        }
    7578
Note: See TracChangeset for help on using the changeset viewer.