Make WordPress Core

Changeset 40731 for branches/4.0


Ignore:
Timestamp:
05/16/2017 02:55:29 PM (9 years ago)
Author:
aaroncampbell
Message:

Add nonce for updating file system credentials.

Merges [40723] to 4.0 branch.

Location:
branches/4.0
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.0

  • branches/4.0/src/wp-admin/includes/file.php

    r29580 r40731  
    976976    $credentials = get_option('ftp_credentials', array( 'hostname' => '', 'username' => ''));
    977977
     978    $submitted_form = wp_unslash( $_POST );
     979
     980    // Verify nonce, or unset submitted form field values on failure
     981    if ( ! isset( $_POST['_fs_nonce'] ) || ! wp_verify_nonce( $_POST['_fs_nonce'], 'filesystem-credentials' ) ) {
     982        unset(
     983            $submitted_form['hostname'],
     984            $submitted_form['username'],
     985            $submitted_form['password'],
     986            $submitted_form['public_key'],
     987            $submitted_form['private_key'],
     988            $submitted_form['connection_type']
     989        );
     990    }
     991
    978992    // If defined, set it to that, Else, If POST'd, set it to that, If not, Set it to whatever it previously was(saved details in option)
    979     $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? wp_unslash( $_POST['hostname'] ) : $credentials['hostname']);
    980     $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? wp_unslash( $_POST['username'] ) : $credentials['username']);
    981     $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? wp_unslash( $_POST['password'] ) : '');
     993    $credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($submitted_form['hostname']) ? $submitted_form['hostname'] : $credentials['hostname']);
     994    $credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($submitted_form['username']) ? $submitted_form['username'] : $credentials['username']);
     995    $credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($submitted_form['password']) ? $submitted_form['password'] : '');
    982996
    983997    // Check to see if we are setting the public/private keys for ssh
    984     $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? wp_unslash( $_POST['public_key'] ) : '');
    985     $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? wp_unslash( $_POST['private_key'] ) : '');
     998    $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($submitted_form['public_key']) ? $submitted_form['public_key'] : '');
     999    $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($submitted_form['private_key']) ? $submitted_form['private_key'] : '');
    9861000
    9871001    // Sanitize the hostname, Some people might pass in odd-data:
     
    10001014    else if ( (defined('FTP_SSL') && FTP_SSL) && 'ftpext' == $type ) //Only the FTP Extension understands SSL
    10011015        $credentials['connection_type'] = 'ftps';
    1002     else if ( !empty($_POST['connection_type']) )
    1003         $credentials['connection_type'] = wp_unslash( $_POST['connection_type'] );
     1016    else if ( !empty($submitted_form['connection_type']) )
     1017        $credentials['connection_type'] = $submitted_form['connection_type'];
    10041018    else if ( !isset($credentials['connection_type']) ) //All else fails (And it's not defaulted to something else saved), Default to FTP
    10051019        $credentials['connection_type'] = 'ftp';
     
    11391153<?php
    11401154foreach ( (array) $extra_fields as $field ) {
    1141     if ( isset( $_POST[ $field ] ) )
    1142         echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( wp_unslash( $_POST[ $field ] ) ) . '" />';
    1143 }
    1144 submit_button( __( 'Proceed' ), 'button', 'upgrade' );
     1155    if ( isset( $submitted_form[ $field ] ) )
     1156        echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( $submitted_form[ $field ] ) . '" />';
     1157}
    11451158?>
     1159    <p class="request-filesystem-credentials-action-buttons">
     1160        <?php wp_nonce_field( 'filesystem-credentials', '_fs_nonce', false, true ); ?>
     1161        <?php submit_button( __( 'Proceed' ), 'button', 'upgrade', false ); ?>
     1162    </p>
    11461163</div>
    11471164</form>
Note: See TracChangeset for help on using the changeset viewer.