Add nonce for updating file system credentials.
Merges [40723] to 4.7 branch. Built from https://develop.svn.wordpress.org/branches/4.7@40724 git-svn-id: http://core.svn.wordpress.org/branches/4.7@40582 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
58075bfc88
commit
a86f61290e
|
@ -1091,14 +1091,28 @@ function request_filesystem_credentials( $form_post, $type = '', $error = false,
|
||||||
|
|
||||||
$credentials = get_option('ftp_credentials', array( 'hostname' => '', 'username' => ''));
|
$credentials = get_option('ftp_credentials', array( 'hostname' => '', 'username' => ''));
|
||||||
|
|
||||||
|
$submitted_form = wp_unslash( $_POST );
|
||||||
|
|
||||||
|
// Verify nonce, or unset submitted form field values on failure
|
||||||
|
if ( ! isset( $_POST['_fs_nonce'] ) || ! wp_verify_nonce( $_POST['_fs_nonce'], 'filesystem-credentials' ) ) {
|
||||||
|
unset(
|
||||||
|
$submitted_form['hostname'],
|
||||||
|
$submitted_form['username'],
|
||||||
|
$submitted_form['password'],
|
||||||
|
$submitted_form['public_key'],
|
||||||
|
$submitted_form['private_key'],
|
||||||
|
$submitted_form['connection_type']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 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)
|
// 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)
|
||||||
$credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($_POST['hostname']) ? wp_unslash( $_POST['hostname'] ) : $credentials['hostname']);
|
$credentials['hostname'] = defined('FTP_HOST') ? FTP_HOST : (!empty($submitted_form['hostname']) ? $submitted_form['hostname'] : $credentials['hostname']);
|
||||||
$credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($_POST['username']) ? wp_unslash( $_POST['username'] ) : $credentials['username']);
|
$credentials['username'] = defined('FTP_USER') ? FTP_USER : (!empty($submitted_form['username']) ? $submitted_form['username'] : $credentials['username']);
|
||||||
$credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($_POST['password']) ? wp_unslash( $_POST['password'] ) : '');
|
$credentials['password'] = defined('FTP_PASS') ? FTP_PASS : (!empty($submitted_form['password']) ? $submitted_form['password'] : '');
|
||||||
|
|
||||||
// Check to see if we are setting the public/private keys for ssh
|
// Check to see if we are setting the public/private keys for ssh
|
||||||
$credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? wp_unslash( $_POST['public_key'] ) : '');
|
$credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($submitted_form['public_key']) ? $submitted_form['public_key'] : '');
|
||||||
$credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? wp_unslash( $_POST['private_key'] ) : '');
|
$credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($submitted_form['private_key']) ? $submitted_form['private_key'] : '');
|
||||||
|
|
||||||
// Sanitize the hostname, Some people might pass in odd-data:
|
// Sanitize the hostname, Some people might pass in odd-data:
|
||||||
$credentials['hostname'] = preg_replace('|\w+://|', '', $credentials['hostname']); //Strip any schemes off
|
$credentials['hostname'] = preg_replace('|\w+://|', '', $credentials['hostname']); //Strip any schemes off
|
||||||
|
@ -1115,8 +1129,8 @@ function request_filesystem_credentials( $form_post, $type = '', $error = false,
|
||||||
$credentials['connection_type'] = 'ssh';
|
$credentials['connection_type'] = 'ssh';
|
||||||
} elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' == $type ) { //Only the FTP Extension understands SSL
|
} elseif ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' == $type ) { //Only the FTP Extension understands SSL
|
||||||
$credentials['connection_type'] = 'ftps';
|
$credentials['connection_type'] = 'ftps';
|
||||||
} elseif ( ! empty( $_POST['connection_type'] ) ) {
|
} elseif ( ! empty( $submitted_form['connection_type'] ) ) {
|
||||||
$credentials['connection_type'] = wp_unslash( $_POST['connection_type'] );
|
$credentials['connection_type'] = $submitted_form['connection_type'];
|
||||||
} elseif ( ! isset( $credentials['connection_type'] ) ) { //All else fails (And it's not defaulted to something else saved), Default to FTP
|
} elseif ( ! isset( $credentials['connection_type'] ) ) { //All else fails (And it's not defaulted to something else saved), Default to FTP
|
||||||
$credentials['connection_type'] = 'ftp';
|
$credentials['connection_type'] = 'ftp';
|
||||||
}
|
}
|
||||||
|
@ -1255,11 +1269,12 @@ if ( isset( $types['ssh'] ) ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ( (array) $extra_fields as $field ) {
|
foreach ( (array) $extra_fields as $field ) {
|
||||||
if ( isset( $_POST[ $field ] ) )
|
if ( isset( $submitted_form[ $field ] ) )
|
||||||
echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( wp_unslash( $_POST[ $field ] ) ) . '" />';
|
echo '<input type="hidden" name="' . esc_attr( $field ) . '" value="' . esc_attr( $submitted_form[ $field ] ) . '" />';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<p class="request-filesystem-credentials-action-buttons">
|
<p class="request-filesystem-credentials-action-buttons">
|
||||||
|
<?php wp_nonce_field( 'filesystem-credentials', '_fs_nonce', false, true ); ?>
|
||||||
<button class="button cancel-button" data-js-action="close" type="button"><?php _e( 'Cancel' ); ?></button>
|
<button class="button cancel-button" data-js-action="close" type="button"><?php _e( 'Cancel' ); ?></button>
|
||||||
<?php submit_button( __( 'Proceed' ), '', 'upgrade', false ); ?>
|
<?php submit_button( __( 'Proceed' ), '', 'upgrade', false ); ?>
|
||||||
</p>
|
</p>
|
||||||
|
|
|
@ -94,6 +94,7 @@
|
||||||
* @type {object} filesystemCredentials.ssh Holds SSH credentials.
|
* @type {object} filesystemCredentials.ssh Holds SSH credentials.
|
||||||
* @type {string} filesystemCredentials.ssh.publicKey The public key. Default empty string.
|
* @type {string} filesystemCredentials.ssh.publicKey The public key. Default empty string.
|
||||||
* @type {string} filesystemCredentials.ssh.privateKey The private key. Default empty string.
|
* @type {string} filesystemCredentials.ssh.privateKey The private key. Default empty string.
|
||||||
|
* @type {string} filesystemCredentials.fsNonce Filesystem credentials form nonce.
|
||||||
* @type {bool} filesystemCredentials.available Whether filesystem credentials have been provided.
|
* @type {bool} filesystemCredentials.available Whether filesystem credentials have been provided.
|
||||||
* Default 'false'.
|
* Default 'false'.
|
||||||
*/
|
*/
|
||||||
|
@ -108,6 +109,7 @@
|
||||||
publicKey: '',
|
publicKey: '',
|
||||||
privateKey: ''
|
privateKey: ''
|
||||||
},
|
},
|
||||||
|
fsNonce: '',
|
||||||
available: false
|
available: false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -225,6 +227,7 @@
|
||||||
options.data = _.extend( data, {
|
options.data = _.extend( data, {
|
||||||
action: action,
|
action: action,
|
||||||
_ajax_nonce: wp.updates.ajaxNonce,
|
_ajax_nonce: wp.updates.ajaxNonce,
|
||||||
|
_fs_nonce: wp.updates.filesystemCredentials.fsNonce,
|
||||||
username: wp.updates.filesystemCredentials.ftp.username,
|
username: wp.updates.filesystemCredentials.ftp.username,
|
||||||
password: wp.updates.filesystemCredentials.ftp.password,
|
password: wp.updates.filesystemCredentials.ftp.password,
|
||||||
hostname: wp.updates.filesystemCredentials.ftp.hostname,
|
hostname: wp.updates.filesystemCredentials.ftp.hostname,
|
||||||
|
@ -1705,6 +1708,7 @@
|
||||||
wp.updates.filesystemCredentials.ftp.connectionType = $( 'input[name="connection_type"]:checked' ).val();
|
wp.updates.filesystemCredentials.ftp.connectionType = $( 'input[name="connection_type"]:checked' ).val();
|
||||||
wp.updates.filesystemCredentials.ssh.publicKey = $( '#public_key' ).val();
|
wp.updates.filesystemCredentials.ssh.publicKey = $( '#public_key' ).val();
|
||||||
wp.updates.filesystemCredentials.ssh.privateKey = $( '#private_key' ).val();
|
wp.updates.filesystemCredentials.ssh.privateKey = $( '#private_key' ).val();
|
||||||
|
wp.updates.filesystemCredentials.fsNonce = $( '#_fs_nonce' ).val();
|
||||||
wp.updates.filesystemCredentials.available = true;
|
wp.updates.filesystemCredentials.available = true;
|
||||||
|
|
||||||
// Unlock and invoke the queue.
|
// Unlock and invoke the queue.
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.7.5-alpha-40717';
|
$wp_version = '4.7.5-alpha-40724';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue