Skip to content

Commit ed31e83

Browse files
committed
Clearing cache security fix
1 parent 0282d97 commit ed31e83

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

includes/admin/admin.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ function crp_load_admin_scripts( $hook ) {
131131
),
132132
)
133133
);
134+
wp_localize_script(
135+
'crp-admin-js',
136+
'crp_admin_data',
137+
array(
138+
'security' => wp_create_nonce( 'crp-admin' ),
139+
)
140+
);
134141

135142
}
136143
}

includes/admin/js/admin-scripts.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22
function crpClearCache() {
33
/**** since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php ****/
44
jQuery.post(ajaxurl, {
5-
action: 'crp_clear_cache'
5+
action: 'crp_clear_cache',
6+
security: crp_admin_data.security
67
}, function (response, textStatus, jqXHR) {
78
alert(response.message);
89
}, 'json');
910
}
1011

1112
jQuery(document).ready(function($) {
1213
// Prompt the user when they leave the page without saving the form.
13-
formmodified=0;
14+
var formmodified=0;
1415

1516
function confirmFormChange() {
1617
formmodified=1;

includes/admin/js/admin-scripts.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

includes/modules/cache.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717
*/
1818
function crp_ajax_clearcache() {
1919

20+
if ( ! current_user_can( 'manage_options' ) ) {
21+
wp_die( 0 );
22+
}
23+
check_ajax_referer( 'crp-admin', 'security' );
24+
2025
crp_cache_delete();
2126
exit(
2227
wp_json_encode(

0 commit comments

Comments
 (0)