diff --git a/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php b/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php index e9f1b7bcf205e..669fedf5601b5 100644 --- a/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php +++ b/projects/plugins/jetpack/modules/widget-visibility/widget-conditions.php @@ -765,8 +765,11 @@ public static function filter_widget( $instance ) { return $instance; } // WordPress.com specific check - here, referer ends in /rest-proxy/ and doesn't tell us what's requesting. - if ( true === isset( $_REQUEST['_gutenberg_nonce'] ) && wp_verify_nonce( $_REQUEST['_gutenberg_nonce'], 'gutenberg_request' ) && - 1 === preg_match( '~^/wp/v2/sites/\d+/(sidebars|widgets)~', $_SERVER['REQUEST_URI'] ) && 'edit' === $_REQUEST['context'] ) { + $current_url = ! empty( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; + $nonce = ! empty( $_REQUEST['_gutenberg_nonce'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['_gutenberg_nonce'] ) ) : ''; + $context = ! empty( $_REQUEST['context'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['context'] ) ) : ''; + if ( wp_verify_nonce( $nonce, 'gutenberg_request' ) && + 1 === preg_match( '~^/wp/v2/sites/\d+/(sidebars|widgets)~', $current_url ) && 'edit' === $context ) { return $instance; }