Changeset 2804133
- Timestamp:
- 10/25/2022 09:43:23 PM (3 years ago)
- Location:
- resmushit-image-optimizer/trunk
- Files:
-
- 5 edited
-
classes/resmushitUI.class.php (modified) (10 diffs)
-
js/script.js (modified) (8 diffs)
-
readme.txt (modified) (2 diffs)
-
resmushit.php (modified) (9 diffs)
-
resmushit.settings.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
resmushit-image-optimizer/trunk/classes/resmushitUI.class.php
r2784230 r2804133 163 163 } 164 164 165 echo wp_kses_post("<div class='rsmt-bulk' ><div class='non-optimized-wrapper $additionnalClassNeedOptimization'><h3 class='icon_message warning'>");166 165 echo wp_kses_post("<div class='rsmt-bulk' data-csrf='" . wp_create_nonce( 'bulk_process_image' ) . "'><div class='non-optimized-wrapper $additionnalClassNeedOptimization'><h3 class='icon_message warning'>"); 166 167 167 if(get_option('resmushit_cron') && get_option('resmushit_cron') == 1) { 168 168 echo wp_kses_post("<em>$countNonOptimizedPictures " … … 186 186 ))); 187 187 188 echo wp_kses("</p><p class='submit' id='bulk-resize-examine-button'><button class='button-primary' onclick='resmushit_bulk_resize(\"bulk_resize_image_list\" );'>", $allowed_html);188 echo wp_kses("</p><p class='submit' id='bulk-resize-examine-button'><button class='button-primary' onclick='resmushit_bulk_resize(\"bulk_resize_image_list\", \"" . wp_create_nonce( 'bulk_resize' ) . "\");'>", $allowed_html); 189 189 190 190 if(get_option('resmushit_cron') && get_option('resmushit_cron') == 1) { … … 320 320 'value' => array(), 321 321 'class' => array(), 322 'name' => array() 322 'name' => array(), 323 'data-csrf' => array(), 323 324 ))); 324 325 … … 327 328 . __('Warning! By clicking the button below, you will restore all the original pictures, as before reSmush.it Image Optimizer installation. You will not have your pictures optimized! We strongly advice to be sure to have a complete backup of your website before performing this action', 'resmushit-image-optimizer') 328 329 . '</strong></p><p>' 329 . '<input type="button" value="'. __('Restore ALL my original pictures', 'resmushit-image-optimizer') .'" class="rsmt-trigger--restore-backup-files button media-button select-mode-toggle-button" name="resmushit" class="button wp-smush-send" />'330 . '<input type="button" data-csrf="'. wp_create_nonce( 'restore_library' ) .'" value="'. __('Restore ALL my original pictures', 'resmushit-image-optimizer') .'" class="rsmt-trigger--restore-backup-files button media-button select-mode-toggle-button" name="resmushit" class="button wp-smush-send" />' 330 331 . '</div>', $allowed_html); 331 332 self::fullWidthPanelEndWrapper(); … … 456 457 'class' => array(), 457 458 'name' => array(), 459 'data-csrf' => array() 458 460 ))); 459 461 echo wp_kses("<div class='rsmt-alert'>" … … 466 468 . sprintf( __( 'We have found %s files ready to be removed', 'resmushit-image-optimizer' ), count(detect_unsmushed_files()) ) 467 469 . '</p><p>' 468 . '<input type="button" value="'. __('Remove backup files', 'resmushit-image-optimizer') .'" class="rsmt-trigger--remove-backup-files button media-button select-mode-toggle-button" name="resmushit" class="button wp-smush-send" />'470 . '<input type="button" value="'. __('Remove backup files', 'resmushit-image-optimizer') .'" data-csrf="'. wp_create_nonce( 'remove_backup' ) .'" class="rsmt-trigger--remove-backup-files button media-button select-mode-toggle-button" name="resmushit" class="button wp-smush-send" />' 469 471 . "</div>", $allowed_html); 470 472 } … … 531 533 $attachment_resmushit_disabled = 'checked'; 532 534 533 $output = '<input type="checkbox" data-attachment-id="'. $id .'"" class="rsmt-trigger--disabled-checkbox" '. $attachment_resmushit_disabled .' />';535 $output = '<input type="checkbox" data-attachment-id="'. $id .'"" data-csrf="'. wp_create_nonce( 'single_attachment' ) .'"" class="rsmt-trigger--disabled-checkbox" '. $attachment_resmushit_disabled .' />'; 534 536 535 537 if($return) … … 539 541 'input' => array( 540 542 'type' => array(), 541 'data- attachment-id' => array(),543 'data-*' => array(), 542 544 'checked' => array(), 543 545 )); … … 561 563 } 562 564 else if(reSmushit::getAttachmentQuality($attachment_id) != reSmushit::getPictureQualitySetting()) 563 $output = '<input type="button" value="'. __('Optimize', 'resmushit-image-optimizer') .'" class="rsmt-trigger--optimize-attachment button media-button select-mode-toggle-button" name="resmushit" data-attachment-id="'. $attachment_id .'" class="button wp-smush-send" />';565 $output = '<input type="button" data-csrf="' . wp_create_nonce( 'single_attachment' ) . '" value="'. __('Optimize', 'resmushit-image-optimizer') .'" class="rsmt-trigger--optimize-attachment button media-button select-mode-toggle-button" name="resmushit" data-attachment-id="'. $attachment_id .'" class="button wp-smush-send" />'; 564 566 else{ 565 567 $statistics = reSmushit::getStatistics($attachment_id); 566 568 $output = __('Reduced by', 'resmushit-image-optimizer') . " ". $statistics['total_saved_size_nice'] ." (". $statistics['percent_reduction'] . ' ' . __('saved', 'resmushit-image-optimizer') . ")"; 567 $output .= '<input type="button" value="'. __('Force re-optimize', 'resmushit-image-optimizer') .'" class="rsmt-trigger--optimize-attachment button media-button select-mode-toggle-button" name="resmushit" data-attachment-id="'. $attachment_id .'" class="button wp-smush-send" />';569 $output .= '<input type="button" data-csrf="' . wp_create_nonce( 'single_attachment' ) . '" value="'. __('Force re-optimize', 'resmushit-image-optimizer') .'" class="rsmt-trigger--optimize-attachment button media-button select-mode-toggle-button" name="resmushit" data-attachment-id="'. $attachment_id .'" class="button wp-smush-send" />'; 568 570 } 569 571 … … 576 578 'class' => array(), 577 579 'name' => array(), 578 'data- attachment-id' => array(),580 'data-*' => array(), 579 581 'checked' => array(), 580 582 ))); -
resmushit-image-optimizer/trunk/js/script.js
r2528324 r2804133 44 44 function resmushit_bulk_process(bulk, item){ 45 45 var error_occured = false; 46 var csrf_token = jQuery('.rsmt-bulk').attr('data-csrf'); 46 47 jQuery.post( 47 48 ajaxurl, { 48 49 action: 'resmushit_bulk_process_image', 49 data: bulk[item] 50 data: bulk[item], 51 csrf: csrf_token 50 52 }, 51 53 function(response) { … … 98 100 * @param string the id of the html element into which results will be appended 99 101 */ 100 function resmushit_bulk_resize(container_id ) {102 function resmushit_bulk_resize(container_id, csrf_token) { 101 103 container = jQuery('#'+container_id); 102 104 container.html('<div id="bulk_resize_target">'); … … 112 114 jQuery.post( 113 115 ajaxurl, 114 { action: 'resmushit_bulk_get_images' },116 { action: 'resmushit_bulk_get_images', csrf: csrf_token }, 115 117 function(response) { 116 var images = JSON.parse(response); 117 if (images.nonoptimized.length > 0) { 118 var images = JSON.parse(response); 119 if (images.hasOwnProperty('error')) { 120 target.html('<div>' + images.error + '.</div>'); 121 } else if (images.hasOwnProperty('nonoptimized') && images.nonoptimized.length > 0) { 118 122 bulkTotalimages = images.nonoptimized.length; 119 123 target.html('<div class="loading--bulk"><span class="loader"></span><br />' + bulkTotalimages + ' attachment(s) found, starting optimization...</div>'); … … 134 138 */ 135 139 function updateStatistics() { 140 var csrf_token = jQuery('.rsmt-bulk').attr('data-csrf'); 136 141 jQuery.post( 137 142 ajaxurl, { 138 action: 'resmushit_update_statistics' 143 action: 'resmushit_update_statistics', 144 csrf: csrf_token 139 145 }, 140 146 function(response) { … … 160 166 var disabledState = jQuery(current).is(':checked'); 161 167 var postID = jQuery(current).attr('data-attachment-id'); 168 var csrfToken = jQuery(current).attr('data-csrf'); 162 169 163 170 jQuery.post( 164 171 ajaxurl, { 165 172 action: 'resmushit_update_disabled_state', 166 data: {id: postID, disabled: disabledState }173 data: {id: postID, disabled: disabledState, csrf: csrfToken} 167 174 }, 168 175 function(response) { … … 200 207 var disabledState = jQuery(current).is(':checked'); 201 208 var postID = jQuery(current).attr('data-attachment-id'); 209 var csrf_token = jQuery(current).attr('data-csrf'); 210 202 211 jQuery.post( 203 212 ajaxurl, { 204 213 action: 'resmushit_optimize_single_attachment', 205 data: {id: postID }214 data: {id: postID, csrf: csrf_token} 206 215 }, 207 216 function(response) { … … 225 234 jQuery(current).val('Removing backups...'); 226 235 jQuery(current).prop('disabled', true); 236 var csrf_token = jQuery(current).attr('data-csrf'); 227 237 jQuery.post( 228 238 ajaxurl, { 229 action: 'resmushit_remove_backup_files' 239 action: 'resmushit_remove_backup_files', 240 csrf: csrf_token 230 241 }, 231 242 function(response) { … … 251 262 jQuery(current).val('Restoring backups...'); 252 263 jQuery(current).prop('disabled', true); 264 var csrf_token = jQuery(current).attr('data-csrf'); 253 265 jQuery.post( 254 266 ajaxurl, { 255 action: 'resmushit_restore_backup_files' 267 action: 'resmushit_restore_backup_files', 268 csrf: csrf_token 256 269 }, 257 270 function(response) { -
resmushit-image-optimizer/trunk/readme.txt
r2784230 r2804133 3 3 Tags: image, optimizer, image optimization, resmush.it, smush, jpg, png, gif, optimization, compression, Compress, Images, Pictures, Reduce Image Size, Smush, Smush.it 4 4 Requires at least: 4.0.0 5 Tested up to: 6.0. 26 Stable tag: 0.4. 65 Tested up to: 6.0.3 6 Stable tag: 0.4.7 7 7 License: GPLv2 or later 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 9 10 The FREE Image Optimizer which will compress your pictures and improve your SEO & performances by using reSmush.it, the 10+ billion images API optimizer.10 The FREE Image Optimizer which will compress your pictures and improve your SEO & performances by using reSmush.it, the 20+ billion images API optimizer. 11 11 12 12 == Description == … … 75 75 == Changelog == 76 76 77 78 = 0.4.7 = 79 * Security fixes : CSRF protection for Ajax Calls 77 80 78 81 = 0.4.6 = -
resmushit-image-optimizer/trunk/resmushit.php
r2784230 r2804133 11 11 * Plugin URI: https://wordpress.org/plugins/resmushit-image-optimizer/ 12 12 * Description: Image Optimization API. Provides image size optimization 13 * Version: 0.4. 614 * Timestamp: 2022. 09.1313 * Version: 0.4.7 14 * Timestamp: 2022.10.25 15 15 * Author: reSmush.it 16 16 * Author URI: https://resmush.it … … 23 23 24 24 require('resmushit.inc.php'); 25 26 25 require_once( ABSPATH . 'wp-includes/pluggable.php' ); 27 26 /** 28 27 * … … 194 193 */ 195 194 function resmushit_bulk_get_images() { 195 if ( !isset($_REQUEST['csrf']) || ! wp_verify_nonce( $_REQUEST['csrf'], 'bulk_resize' ) ) { 196 wp_send_json(json_encode(array('error' => 'Invalid CSRF token'))); 197 die(); 198 } 196 199 if(!is_super_admin() && !current_user_can('administrator')) { 197 200 wp_send_json(json_encode(array('error' => 'User must be at least administrator to retrieve these data'))); … … 214 217 */ 215 218 function resmushit_update_disabled_state() { 219 if ( !isset($_REQUEST['data']['csrf']) || ! wp_verify_nonce( $_REQUEST['data']['csrf'], 'single_attachment' ) ) { 220 wp_send_json(json_encode(array('error' => 'Invalid CSRF token'))); 221 die(); 222 } 216 223 if(!is_super_admin() && !current_user_can('administrator')) { 217 224 wp_send_json(json_encode(array('error' => 'User must be at least administrator to retrieve these data'))); … … 237 244 */ 238 245 function resmushit_optimize_single_attachment() { 246 if ( !isset($_REQUEST['data']['csrf']) || ! wp_verify_nonce( $_REQUEST['data']['csrf'], 'single_attachment' ) ) { 247 wp_send_json(json_encode(array('error' => 'Invalid CSRF token'))); 248 die(); 249 } 239 250 if(!is_super_admin() && !current_user_can('administrator')) { 240 251 wp_send_json(json_encode(array('error' => 'User must be at least administrator to retrieve these data'))); … … 261 272 */ 262 273 function resmushit_bulk_process_image() { 274 if ( !isset($_REQUEST['csrf']) || ! wp_verify_nonce( $_REQUEST['csrf'], 'bulk_process_image' ) ) { 275 wp_send_json(json_encode(array('error' => 'Invalid CSRF token'))); 276 die(); 277 } 263 278 if(!is_super_admin() && !current_user_can('administrator')) { 264 279 wp_send_json(json_encode(array('error' => 'User must be at least administrator to retrieve these data'))); … … 283 298 */ 284 299 function resmushit_update_statistics() { 300 if ( !isset($_REQUEST['csrf']) || ! wp_verify_nonce( $_REQUEST['csrf'], 'bulk_process_image' ) ) { 301 wp_send_json(json_encode(array('error' => 'Invalid CSRF token'))); 302 die(); 303 } 285 304 if(!is_super_admin() && !current_user_can('administrator')) { 286 305 wp_send_json(json_encode(array('error' => 'User must be at least administrator to retrieve these data'))); … … 453 472 function resmushit_remove_backup_files() { 454 473 $return = array('success' => 0); 474 if ( !isset($_REQUEST['csrf']) || ! wp_verify_nonce( $_REQUEST['csrf'], 'remove_backup' ) ) { 475 wp_send_json(json_encode(array('error' => 'Invalid CSRF token'))); 476 die(); 477 } 455 478 if(!is_super_admin() && !current_user_can('administrator')) { 456 479 wp_send_json(json_encode(array('error' => 'User must be at least administrator to retrieve these data'))); … … 495 518 */ 496 519 function resmushit_restore_backup_files() { 520 if ( !isset($_REQUEST['csrf']) || ! wp_verify_nonce( $_REQUEST['csrf'], 'restore_library' ) ) { 521 wp_send_json(json_encode(array('error' => 'Invalid CSRF token'))); 522 die(); 523 } 497 524 if(!is_super_admin() && !current_user_can('administrator')) { 498 525 wp_send_json(json_encode(array('error' => 'User must be at least administrator to retrieve these data'))); -
resmushit-image-optimizer/trunk/resmushit.settings.php
r2784230 r2804133 2 2 3 3 define('RESMUSHIT_ENDPOINT', 'http://api.resmush.it/'); 4 define('RESMUSHIT_VERSION', '0.4. 6');4 define('RESMUSHIT_VERSION', '0.4.7'); 5 5 define('RESMUSHIT_DEFAULT_QLTY', '92'); 6 6 define('RESMUSHIT_TIMEOUT', '10');
Note: See TracChangeset
for help on using the changeset viewer.