Make WordPress Core

Changeset 46504


Ignore:
Timestamp:
10/14/2019 07:29:52 PM (6 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.
  • Customizer: Properly sanitize background images.

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

Location:
branches/3.8
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/3.8

  • branches/3.8/package.json

    r46032 r46504  
    2121    "grunt-contrib-jshint": "~0.7.0",
    2222    "grunt-cssjanus": "git://github.com/yoavf/grunt-cssjanus.git#e0158f4087d1c4bb5a8d1648a63ef133338b5879",
    23     "grunt-sass": "~0.8.0",
     23    "grunt-sass": "~1.0.0",
    2424    "matchdep": "~0.1.2"
    2525  }
  • branches/3.8/src/wp-includes/class-wp.php

    r44073 r46504  
    1616     * @var array
    1717     */
    18     var $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', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type');
     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', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type', 'embed' );
    1919
    2020    /**
  • branches/3.8/src/wp-includes/functions.php

    r44011 r46504  
    13611361    if ( file_exists( $target ) )
    13621362        return @is_dir( $target );
     1363
     1364    // Do not allow path traversals.
     1365    if ( false !== strpos( $target, '../' ) || false !== strpos( $target, '..' . DIRECTORY_SEPARATOR ) ) {
     1366        return false;
     1367    }
    13631368
    13641369    // We need to find the permissions of the parent folder that exists and inherit that.
  • branches/3.8/src/wp-includes/http.php

    r37122 r46504  
    477477        } else {
    478478            $ip = gethostbyname( $host );
    479             if ( $ip === $host ) // Error condition for gethostbyname()
    480                 $ip = false;
     479            if ( $ip === $host ) { // Error condition for gethostbyname()
     480                return false;
     481            }
    481482        }
    482483        if ( $ip ) {
  • branches/3.8/src/wp-includes/pluggable.php

    r45987 r46504  
    806806 * @param string $query_arg where to look for nonce in $_REQUEST (since 2.5)
    807807 */
    808 function check_admin_referer($action = -1, $query_arg = '_wpnonce') {
    809     if ( -1 == $action )
    810         _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2' );
     808function check_admin_referer( $action = -1, $query_arg = '_wpnonce' ) {
     809    if ( -1 === $action )
     810        _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2.0' );
    811811
    812812    $adminurl = strtolower(admin_url());
    813813    $referer = strtolower(wp_get_referer());
    814814    $result = isset($_REQUEST[$query_arg]) ? wp_verify_nonce($_REQUEST[$query_arg], $action) : false;
    815     if ( !$result && !(-1 == $action && strpos($referer, $adminurl) === 0) ) {
    816         wp_nonce_ays($action);
     815
     816    /**
     817     * Fires once the admin request has been validated or not.
     818     *
     819     * @since 1.5.1
     820     *
     821     * @param string $action The nonce action.
     822     * @param bool   $result Whether the admin request nonce was validated.
     823     */
     824    do_action( 'check_admin_referer', $action, $result );
     825
     826    if ( ! $result && ! ( -1 === $action && strpos( $referer, $adminurl ) === 0 ) ) {
     827        wp_nonce_ays( $action );
    817828        die();
    818829    }
    819     do_action('check_admin_referer', $action, $result);
     830
    820831    return $result;
    821832}
     
    832843 */
    833844function check_ajax_referer( $action = -1, $query_arg = false, $die = true ) {
     845    if ( -1 === $action )
     846        _doing_it_wrong( __FUNCTION__, __( 'You should specify a nonce action to be verified by using the first parameter.' ), '3.2.0' );
     847
    834848    $nonce = '';
    835849
     
    18581872}
    18591873endif;
    1860 
    1861 if ( ! function_exists( 'hash_equals' ) ) :
    1862 /**
    1863  * Compare two strings in constant time.
    1864  *
    1865  * This function is NOT pluggable. It is in this file (in addition to
    1866  * compat.php) to prevent errors if, during an update, pluggable.php
    1867  * copies over but compat.php does not.
    1868  *
    1869  * This function was added in PHP 5.6.
    1870  * It can leak the length of a string.
    1871  *
    1872  * @since 3.9.2
    1873  *
    1874  * @param string $a Expected string.
    1875  * @param string $b Actual string.
    1876  * @return bool Whether strings are equal.
    1877  */
    1878 function hash_equals( $a, $b ) {
    1879     $a_length = strlen( $a );
    1880     if ( $a_length !== strlen( $b ) ) {
    1881         return false;
    1882     }
    1883     $result = 0;
    1884 
    1885     // Do not attempt to "optimize" this.
    1886     for ( $i = 0; $i < $a_length; $i++ ) {
    1887         $result |= ord( $a[ $i ] ) ^ ord( $b[ $i ] );
    1888     }
    1889 
    1890     return $result === 0;
    1891 }
    1892 endif;
  • branches/3.8/src/wp-includes/query.php

    r39965 r46504  
    13971397            , 'attachment_id'
    13981398            , 'name'
    1399             , 'static'
    14001399            , 'pagename'
    14011400            , 'page_id'
     
    15051504            // post is being queried.
    15061505            $this->is_single = true;
    1507         } elseif ( '' != $qv['static'] || '' != $qv['pagename'] || !empty($qv['page_id']) ) {
     1506        } elseif ( '' != $qv['pagename'] || !empty($qv['page_id']) ) {
    15081507            $this->is_page = true;
    15091508            $this->is_single = false;
  • branches/3.8/tests/phpunit/tests/auth.php

    r30469 r46504  
    9494    }
    9595
     96    /**
     97     * @ticket 29217
     98     */
     99    function test_wp_verify_nonce_with_empty_arg() {
     100        $this->assertFalse( wp_verify_nonce( '' ) );
     101        $this->assertFalse( wp_verify_nonce( null ) );
     102    }
     103
     104    /**
     105     * @ticket 29542
     106     */
     107    function test_wp_verify_nonce_with_integer_arg() {
     108        $this->assertFalse( wp_verify_nonce( 1 ) );
     109    }
     110
     111    /**
     112     * @ticket 36361
     113     */
     114    public function test_check_admin_referer_with_no_action_triggers_doing_it_wrong() {
     115        $this->setExpectedIncorrectUsage( 'check_admin_referer' );
     116
     117        // A valid nonce needs to be set so the check doesn't die()
     118        $_REQUEST['_wpnonce'] = wp_create_nonce( -1 );
     119        $result = check_admin_referer();
     120        $this->assertSame( 1, $result );
     121
     122        unset( $_REQUEST['_wpnonce'] );
     123    }
     124
     125    /**
     126     * @ticket 36361
     127     */
     128    public function test_check_ajax_referer_with_no_action_triggers_doing_it_wrong() {
     129        $this->setExpectedIncorrectUsage( 'check_ajax_referer' );
     130
     131        // A valid nonce needs to be set so the check doesn't die()
     132        $_REQUEST['_wpnonce'] = wp_create_nonce( -1 );
     133        $result = check_ajax_referer();
     134        $this->assertSame( 1, $result );
     135
     136        unset( $_REQUEST['_wpnonce'] );
     137    }
     138
    96139    function test_password_length_limit() {
    97140        $passwords = array(
Note: See TracChangeset for help on using the changeset viewer.