Skip to content

Commit 0a9feec

Browse files
committed
Check user permissions for subscriber actions.
1 parent 79f7a04 commit 0a9feec

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/Telemetry/Exit_Interview/Exit_Interview_Subscriber.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ public function render_exit_interview() {
8080
* @return void
8181
*/
8282
public function ajax_exit_interview() {
83+
$nonce = filter_input( INPUT_POST, 'nonce', FILTER_SANITIZE_SPECIAL_CHARS );
84+
$nonce = ! empty( $nonce ) ? $nonce : '';
85+
86+
if ( ! wp_verify_nonce( $nonce, self::AJAX_ACTION ) ) {
87+
wp_send_json_error( 'Invalid nonce' );
88+
}
89+
90+
// Check if the user has the necessary permissions.
91+
if ( ! current_user_can( 'manage_options' ) ) {
92+
wp_send_json_error( 'User does not have proper permissions plugins' );
93+
}
94+
8395
$uninstall_reason_id = filter_input( INPUT_POST, 'uninstall_reason_id', FILTER_SANITIZE_SPECIAL_CHARS );
8496
$uninstall_reason_id = ! empty( $uninstall_reason_id ) ? $uninstall_reason_id : false;
8597
if ( ! $uninstall_reason_id ) {
@@ -97,13 +109,6 @@ public function ajax_exit_interview() {
97109
$comment = filter_input( INPUT_POST, 'comment', FILTER_SANITIZE_SPECIAL_CHARS );
98110
$comment = ! empty( $comment ) ? $comment : '';
99111

100-
$nonce = filter_input( INPUT_POST, 'nonce', FILTER_SANITIZE_SPECIAL_CHARS );
101-
$nonce = ! empty( $nonce ) ? $nonce : '';
102-
103-
if ( ! wp_verify_nonce( $nonce, self::AJAX_ACTION ) ) {
104-
wp_send_json_error( 'Invalid nonce' );
105-
}
106-
107112
$telemetry = $this->container->get( Telemetry::class );
108113
$telemetry->send_uninstall( $plugin_slug, $uninstall_reason_id, $uninstall_reason, $comment );
109114

src/Telemetry/Opt_In/Opt_In_Subscriber.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public function set_optin_status() {
6161
return;
6262
}
6363

64+
if ( ! current_user_can( 'manage_options' ) ) {
65+
return;
66+
}
67+
6468
// We're not attempting a telemetry action.
6569
if ( isset( $_POST['action'] ) && 'stellarwp-telemetry' !== $_POST['action'] ) {
6670
return;

0 commit comments

Comments
 (0)