Skip to content

Commit 5c9fb59

Browse files
authored
Harden preload status AJAX endpoint (#1032)
1 parent e10f5be commit 5c9fb59

3 files changed

Lines changed: 8 additions & 0 deletions

File tree

inc/preload-notification.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function wpsc_preload_notification_scripts() {
2020
'wpsc_preload_ajax',
2121
array(
2222
'ajax_url' => admin_url( 'admin-ajax.php' ),
23+
'nonce' => wp_create_nonce( 'wpsc-get-preload-status' ),
2324
'preload_status' => wpsc_get_preload_status( true ),
2425
)
2526
);

js/preload-notification.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jQuery( document ).ready( function () {
2828
window.wpsc_preload_ajax.ajax_url,
2929
{
3030
action: 'wpsc_get_preload_status',
31+
_ajax_nonce: window.wpsc_preload_ajax.nonce,
3132
},
3233
json => {
3334
if ( ! json || ! json.success ) {

wp-cache.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3318,6 +3318,12 @@ function clear_post_supercache( $post_id ) {
33183318
* Serves an AJAX endpoint to return the current state of the preload process.
33193319
*/
33203320
function wpsc_ajax_get_preload_status() {
3321+
check_ajax_referer( 'wpsc-get-preload-status' );
3322+
3323+
if ( ! current_user_can( 'manage_options' ) ) {
3324+
wp_send_json_error( null, 403 );
3325+
}
3326+
33213327
$preload_status = wpsc_get_preload_status( true );
33223328
wp_send_json_success( $preload_status, null, JSON_UNESCAPED_SLASHES );
33233329
}

0 commit comments

Comments
 (0)