Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More nonce verifications #3932

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion includes/classes/AdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -589,10 +589,17 @@ protected function process_host_error_notice() {
$response_error = get_transient( 'ep_es_info_response_error' );
}

$retry_url = add_query_arg(
[
'ep-retry' => 1,
'ep_retry_nonce' => wp_create_nonce( 'ep_retry_nonce' ),
]
);

$html = sprintf(
/* translators: 1. Current URL with retry parameter; 2. Settings Page URL */
__( 'There is a problem with connecting to your Elasticsearch host. ElasticPress can <a href="%1$s">try your host again</a>, or you may need to <a href="%2$s">change your settings</a>.', 'elasticpress' ),
esc_url( add_query_arg( 'ep-retry', 1 ) ),
esc_url( $retry_url ),
esc_url( $url )
);

Expand Down
4 changes: 2 additions & 2 deletions includes/classes/Feature/WooCommerce/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,9 @@ public function __call( $method_name, $arguments ) {

if ( in_array( $method_name, $orders_autosuggest_methods, true ) ) {
_deprecated_function(
"\ElasticPress\Feature\WooCommerce\WooCommerce\Orders::{$method_name}", // phpcs:ignore
"\ElasticPress\Feature\WooCommerce\WooCommerce\Orders::{$method_name}", // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
'4.7.0',
"\ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' )->orders_autosuggest->{$method_name}()" // phpcs:ignore
"\ElasticPress\Features::factory()->get_registered_feature( 'woocommerce' )->orders_autosuggest->{$method_name}()" // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
);

if ( $this->woocommerce->orders_autosuggest->is_enabled() && method_exists( $this->woocommerce->orders_autosuggest, $method_name ) ) {
Expand Down
4 changes: 2 additions & 2 deletions includes/classes/Feature/WooCommerce/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ public function translate_args_admin_products_list( $query ) {
// WooCommerce unsets the search term right after using it to fetch product IDs. Here we add it back.
$search_term = ! empty( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification
if ( ! empty( $search_term ) ) {
$query->set( 's', sanitize_text_field( $search_term ) ); // phpcs:ignore WordPress.Security.NonceVerification
$query->set( 's', sanitize_text_field( $search_term ) );

/**
* Filter the fields used in WooCommerce Admin Product Search.
Expand Down Expand Up @@ -973,7 +973,7 @@ protected function maybe_set_orderby( \WP_Query $query ) {
*/
if ( ! empty( $_GET['orderby'] ) && $query->is_main_query() ) { // phpcs:ignore WordPress.Security.NonceVerification
$orderby = sanitize_text_field( wp_unslash( $_GET['orderby'] ) ); // phpcs:ignore WordPress.Security.NonceVerification
switch ( $orderby ) { // phpcs:ignore WordPress.Security.NonceVerification
switch ( $orderby ) {
case 'popularity':
$query->set( 'orderby', $this->get_orderby_meta_mapping( 'total_sales' ) );
$query->set( 'order', 'DESC' );
Expand Down
2 changes: 1 addition & 1 deletion includes/classes/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function calculate_install_status() {

$host = Utils\get_host();

if ( empty( $host ) && empty( $_POST['ep_host'] ) ) { // phpcs:ignore
if ( empty( $host ) && empty( $_POST['ep_host'] ) ) {
$this->install_status = 2;

return;
Expand Down
2 changes: 1 addition & 1 deletion includes/classes/StatusReport/FailedQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function get_actions() : array {
* If a nonce is present, clear the logs
*/
protected function maybe_clear_logs() {
if ( empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'ep-clear-logged-queries' ) ) { // phpcs:ignore WordPress.Security.NonceVerification
if ( empty( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['_wpnonce'] ), 'ep-clear-logged-queries' ) ) {
return;
}

Expand Down
12 changes: 8 additions & 4 deletions includes/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function maybe_skip_install() {
return;
}

if ( empty( $_GET['ep-skip-install'] ) || empty( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['nonce'] ), 'ep-skip-install' ) || ! in_array( Screen::factory()->get_current_screen(), [ 'install' ], true ) ) { // phpcs:ignore WordPress.Security.NonceVerification
if ( empty( $_GET['ep-skip-install'] ) || empty( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_GET['nonce'] ), 'ep-skip-install' ) || ! in_array( Screen::factory()->get_current_screen(), [ 'install' ], true ) ) {
return;
}

Expand Down Expand Up @@ -221,7 +221,11 @@ function maybe_clear_es_info_cache() {
return;
}

if ( empty( $_GET['ep-retry'] ) && ! in_array( Screen::factory()->get_current_screen(), [ 'dashboard', 'settings', 'install' ], true ) ) { // phpcs:ignore WordPress.Security.NonceVerification
$isset_retry = ! empty( $_GET['ep-retry'] ) &&
! empty( $_GET['ep_retry_nonce'] ) &&
wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['ep_retry_nonce'] ) ), 'ep_retry_nonce' );

if ( ! $isset_retry && ! in_array( Screen::factory()->get_current_screen(), [ 'dashboard', 'settings', 'install' ], true ) ) {
return;
}

Expand All @@ -231,8 +235,8 @@ function maybe_clear_es_info_cache() {
delete_transient( 'ep_es_info' );
}

if ( ! empty( $_GET['ep-retry'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
wp_safe_redirect( remove_query_arg( 'ep-retry' ) );
if ( $isset_retry ) {
wp_safe_redirect( remove_query_arg( [ 'ep-retry', 'ep_retry_nonce' ] ) );
exit();
}
}
Expand Down
Loading