@@ -1509,8 +1509,17 @@ public function add_uwp_plupload_param( $params ) {
15091509 * @return void
15101510 */
15111511 public function ajax_avatar_banner_upload () {
1512- // Image upload handler
1513- // todo: security checks
1512+
1513+ if ( ! isset ( $ _POST ['security ' ] ) || ! wp_verify_nonce ( $ _POST ['security ' ], 'uwp_avatar_banner_upload_nonce ' ) ) {
1514+ $ result ['error ' ] = aui ()->alert ( array (
1515+ 'type ' => 'danger ' ,
1516+ 'content ' => __ ( "Security check failed. " , "userswp " )
1517+ ) );
1518+ $ return = json_encode ( $ result );
1519+ echo $ return ; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
1520+ die ();
1521+ }
1522+
15141523 $ type = strip_tags ( esc_sql ( $ _POST ['uwp_popup_type ' ] ) );
15151524 $ result = array ();
15161525
@@ -1764,6 +1773,8 @@ public function crop_submit_form( $type = 'avatar' ) {
17641773
17651774 $ content_wrap = $ design_style == 'bootstrap ' ? '.uwp-profile-image-change-modal .modal-content ' : '#uwp-popup-modal-wrap ' ;
17661775 $ bg_color = apply_filters ('uwp_crop_image_bg_color ' , '' , $ type );
1776+
1777+ $ ajax_nonce = wp_create_nonce ( 'uwp_avatar_banner_upload_nonce ' );
17671778 ?>
17681779
17691780 <script type="text/javascript">
@@ -1805,6 +1816,8 @@ public function crop_submit_form( $type = 'avatar' ) {
18051816 // our AJAX identifier
18061817 fd.append('action', 'uwp_avatar_banner_upload');
18071818 fd.append('uwp_popup_type', '<?php echo esc_attr ( $ type ); ?> ');
1819+ // Add nonce for security
1820+ fd.append('security', '<?php echo esc_js ( $ ajax_nonce ); ?> ');
18081821
18091822 $("#progressBar").show().removeClass('d-none');
18101823
@@ -1853,7 +1866,8 @@ public function crop_submit_form( $type = 'avatar' ) {
18531866 minSize: [uwp_full_width, uwp_full_height]
18541867 });
18551868 }
1856- }
1869+ },
1870+
18571871 });
18581872 });
18591873
0 commit comments