Skip to content

Commit 2f31380

Browse files
Merge pull request #1066 from Codeinwp/bugfix/pro/634
fix: nonce verification
2 parents f83dac7 + a082633 commit 2f31380

4 files changed

Lines changed: 25 additions & 32 deletions

File tree

cron-system/assets/js/debug-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
{
8585
type: "GET",
8686
url: ajaxurl,
87-
data: { 'action': 'reset_local_auth_key' },
87+
data: { 'action': 'reset_local_auth_key', 'nonce': rop_debug.nonce },
8888
dataType: 'json', // xml, html, script, json, jsonp, text
8989
success: function ( data ) {
9090
if ( true === data.success ) {
@@ -143,7 +143,7 @@
143143
{
144144
type: "GET",
145145
url: ajaxurl,
146-
data: { 'action': 'remove_remote_account' },
146+
data: { 'action': 'remove_remote_account', 'nonce': rop_debug.nonce },
147147
dataType: 'json', // xml, html, script, json, jsonp, text
148148
success: function ( data ) {
149149
if ( true === data.success ) {

cron-system/includes/class-debug-page.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ function __construct() {
4343
* Used to delete the remote user account.
4444
*/
4545
public function cron_system_delete_account() {
46+
47+
if ( ! isset( $_GET['nonce'] ) || empty( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'rop_debug' ) ) {
48+
wp_send_json_error( array( 'message' => __( 'Nonce is invalid', 'tweet-old-post' ) ) );
49+
}
50+
51+
if ( ! current_user_can( 'manage_options' ) ) {
52+
wp_send_json_error( array( 'message' => __( 'Insufficient permissions', 'tweet-old-post' ) ) );
53+
}
54+
4655
$response = array();
4756

4857
$token = get_option( 'rop_access_token', '' );
@@ -83,6 +92,15 @@ public function cron_system_delete_account() {
8392
* @since 0.0.1
8493
*/
8594
public function reset_local_client() {
95+
96+
if ( ! isset( $_GET['nonce'] ) || empty( $_GET['nonce'] ) || ! wp_verify_nonce( $_GET['nonce'], 'rop_debug' ) ) {
97+
wp_send_json_error( array( 'message' => __( 'Nonce is invalid', 'tweet-old-post' ) ) );
98+
}
99+
100+
if ( ! current_user_can( 'manage_options' ) ) {
101+
wp_send_json_error( array( 'message' => __( 'Insufficient permissions', 'tweet-old-post' ) ) );
102+
}
103+
86104
$response = array();
87105

88106
// Delete local key.
@@ -110,16 +128,10 @@ public function load_custom_wp_admin_style( $hook ) {
110128
// Load the JS library ony on this page
111129
if ( 'revive-old-posts_page_rop_service_debug' === $hook ) {
112130
wp_enqueue_script( 'rop-debug', ROP_LITE_URL . 'cron-system/assets/js/debug-test.js', array( 'jquery' ), '1.0.0', true );
113-
// Generate a pseudo-random string of bytes.
114-
$random_key = Rop_Helpers::openssl_random_pseudo_bytes();
115-
// Auth token creation.
116-
$created_token = hash( 'sha256', SECURE_AUTH_SALT . $random_key, false );
117-
118-
update_option( 'rop_temp_debug', $created_token, 'no' );
119131

120132
$data_tables = array(
121133
'local_url' => get_site_url() . '/wp-json/tweet-old-post-cron/v1/debug-test/',
122-
'nonce' => $created_token,
134+
'nonce' => wp_create_nonce( 'rop_debug' ),
123135
'remote_url' => ROP_CRON_DOMAIN . '/wp-json/account-status/v1/debug-test/',
124136
'action_success' => __( 'Request completed', 'tweet-old-post' ),
125137
'action_fail' => __( 'Requested failed to complete.', 'tweet-old-post' ),

cron-system/rest-endpoints/class-rop-debug-ping.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,20 +96,13 @@ public function register_routes() {
9696
* @access public
9797
*/
9898
public function process_the_request( WP_REST_Request $request ) {
99-
$key = $request->get_param( 'secret_temp_key' );
100-
$local_key = trim( get_option( 'rop_temp_debug', '' ) );
99+
$key = $request->get_param( 'secret_temp_key' );
101100

102-
$return_data = array(
103-
'success' => false,
104-
);
105-
106-
if ( ! empty( $local_key ) ) {
107-
if ( $key === $local_key ) {
108-
$return_data['success'] = true;
109-
}
101+
if ( ! empty( $key ) || ! wp_verify_nonce( $key, 'rop_debug' ) ) {
102+
return array( 'success' => false );
110103
}
111104

112-
wp_send_json( $return_data );
105+
return array( 'success' => true );
113106
}
114107

115108
/**

phpstan-baseline.neon

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ parameters:
102102
count: 1
103103
path: cron-system/class-rop-cron-core.php
104104

105-
-
106-
message: '#^Constant SECURE_AUTH_SALT not found\.$#'
107-
identifier: constant.notFound
108-
count: 1
109-
path: cron-system/includes/class-debug-page.php
110-
111105
-
112106
message: '#^Method RopCronSystem\\Pages\\Debug_Page\:\:cron_system_delete_account\(\) has no return type specified\.$#'
113107
identifier: missingType.return
@@ -138,12 +132,6 @@ parameters:
138132
count: 1
139133
path: cron-system/includes/class-debug-page.php
140134

141-
-
142-
message: '#^Parameter \#3 \$autoload of function update_option expects bool\|null, string given\.$#'
143-
identifier: argument.type
144-
count: 1
145-
path: cron-system/includes/class-debug-page.php
146-
147135
-
148136
message: '#^Constant SECURE_AUTH_SALT not found\.$#'
149137
identifier: constant.notFound

0 commit comments

Comments
 (0)