@@ -437,15 +437,18 @@ public function async_compress_on_upload( $metadata, $attachment_id ) {
437437 public function process_rpc_request () {
438438 if (
439439 empty ( $ _POST ['tiny_rpc_action ' ] ) ||
440- empty ( $ _POST ['tiny_rpc_hash ' ] ) ||
441- 32 !== strlen ( $ _POST ['tiny_rpc_hash ' ] )
440+ empty ( $ _POST ['tiny_rpc_hash ' ] )
442441 ) {
443442 exit ();
444443 }
445444
446- $ rpc_hash = sanitize_key ( $ _POST ['tiny_rpc_hash ' ] );
447- $ user_id = absint ( get_transient ( 'tiny_rpc_ ' . $ rpc_hash ) );
448- $ user = $ user_id ? get_userdata ( $ user_id ) : false ;
445+ $ rpc_hash = sanitize_key ( wp_unslash ( $ _POST ['tiny_rpc_hash ' ] ) );
446+ if ( 32 !== strlen ( $ rpc_hash ) ) {
447+ exit ();
448+ }
449+
450+ $ user_id = absint ( get_transient ( 'tiny_rpc_ ' . $ rpc_hash ) );
451+ $ user = $ user_id ? get_userdata ( $ user_id ) : false ;
449452
450453 /* We no longer need the transient. */
451454 delete_transient ( 'tiny_rpc_ ' . $ rpc_hash );
@@ -460,7 +463,7 @@ public function process_rpc_request() {
460463 }
461464
462465 /* Now that everything is checked, perform the actual action. */
463- $ action = $ _POST ['tiny_rpc_action ' ];
466+ $ action = sanitize_key ( wp_unslash ( $ _POST ['tiny_rpc_action ' ] ) ) ;
464467 unset(
465468 $ _POST ['action ' ],
466469 $ _POST ['tiny_rpc_action ' ],
@@ -471,12 +474,17 @@ public function process_rpc_request() {
471474 }
472475
473476 public function compress_on_upload () {
474- if ( ! wp_verify_nonce ( $ _POST ['_ajax_nonce ' ], 'new_media- ' . $ _POST ['attachment_id ' ] ) ) {
477+ $ nonce = isset ( $ _POST ['_ajax_nonce ' ] ) ?
478+ sanitize_key ( wp_unslash ( $ _POST ['_ajax_nonce ' ] ) ) : '' ;
479+ $ attachment_id = isset ( $ _POST ['attachment_id ' ] ) ?
480+ intval ( wp_unslash ( $ _POST ['attachment_id ' ] ) ) : 0 ;
481+
482+ if ( ! wp_verify_nonce ( $ nonce , 'new_media- ' . $ attachment_id ) ) {
475483 exit ;
476484 }
477485 if ( current_user_can ( 'upload_files ' ) ) {
478- $ attachment_id = intval ( $ _POST [ ' attachment_id ' ] );
479- $ metadata = $ _POST ['metadata ' ];
486+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
487+ $ metadata = isset ( $ _POST [ ' metadata ' ] ) ? wp_unslash ( $ _POST ['metadata ' ] ) : array () ;
480488 if ( is_array ( $ metadata ) ) {
481489 $ tiny_image = new Tiny_Image ( $ this ->settings , $ attachment_id , $ metadata );
482490
@@ -606,7 +614,9 @@ public function compress_image_for_bulk() {
606614 );
607615 wp_update_attachment_metadata ( $ id , $ tiny_image ->get_wp_metadata () );
608616
609- $ current_library_size = intval ( $ _POST ['current_size ' ] );
617+ $ current_library_size = isset ( $ _POST ['current_size ' ] ) ?
618+ intval ( wp_unslash ( $ _POST ['current_size ' ] ) )
619+ : 0 ;
610620 $ size_after = $ image_statistics ['compressed_total_size ' ];
611621 $ new_library_size = $ current_library_size + $ size_after - $ size_before ;
612622
@@ -670,33 +680,46 @@ public function ajax_compression_status() {
670680
671681 public function media_library_bulk_action () {
672682 $ valid_actions = array ( 'tiny_bulk_action ' , 'tiny_bulk_mark_compressed ' );
673- $ action = isset ( $ _REQUEST ['action ' ] ) ? $ _REQUEST ['action ' ] : '' ;
674- $ action2 = isset ( $ _REQUEST ['action2 ' ] ) ? $ _REQUEST ['action2 ' ] : '' ;
683+ $ action = isset ( $ _REQUEST ['action ' ] ) ?
684+ sanitize_key ( wp_unslash ( $ _REQUEST ['action ' ] ) ) : '' ;
685+ $ action2 = isset ( $ _REQUEST ['action2 ' ] ) ?
686+ sanitize_key ( wp_unslash ( $ _REQUEST ['action2 ' ] ) ) : '' ;
675687
676688 if (
677689 ! in_array ( $ action , $ valid_actions , true ) &&
678690 ! in_array ( $ action2 , $ valid_actions , true )
679691 ) {
680692 return ;
681693 }
682- if ( empty ( $ _REQUEST ['media ' ] ) || ( ! $ _REQUEST ['media ' ] ) ) {
694+ $ media = isset ( $ _REQUEST ['media ' ] ) ?
695+ array_map ( 'intval ' , wp_unslash ( (array ) $ _REQUEST ['media ' ] ) )
696+ : array ();
697+ if ( empty ( $ media ) ) {
683698 $ _REQUEST ['action ' ] = '' ;
684699 return ;
685700 }
686701 check_admin_referer ( 'bulk-media ' );
687- $ ids = implode ( '- ' , array_map ( ' intval ' , $ _REQUEST [ ' media ' ] ) );
702+ $ ids = implode ( '- ' , $ media );
688703 $ location = 'upload.php?mode=list&ids= ' . $ ids ;
689704
690- $ location = add_query_arg ( 'action ' , $ _REQUEST [ ' action ' ] , $ location );
705+ $ location = add_query_arg ( 'action ' , $ action , $ location );
691706
692707 if ( ! empty ( $ _REQUEST ['paged ' ] ) ) {
693708 $ location = add_query_arg ( 'paged ' , absint ( $ _REQUEST ['paged ' ] ), $ location );
694709 }
695710 if ( ! empty ( $ _REQUEST ['s ' ] ) ) {
696- $ location = add_query_arg ( 's ' , $ _REQUEST ['s ' ], $ location );
711+ $ location = add_query_arg (
712+ 's ' ,
713+ sanitize_text_field ( wp_unslash ( $ _REQUEST ['s ' ] ) ),
714+ $ location
715+ );
697716 }
698717 if ( ! empty ( $ _REQUEST ['m ' ] ) ) {
699- $ location = add_query_arg ( 'm ' , $ _REQUEST ['m ' ], $ location );
718+ $ location = add_query_arg (
719+ 'm ' ,
720+ sanitize_text_field ( wp_unslash ( $ _REQUEST ['m ' ] ) ),
721+ $ location
722+ );
700723 }
701724
702725 wp_safe_redirect ( admin_url ( $ location ) );
0 commit comments