@@ -566,22 +566,31 @@ public static function display_settings( $site ) {
566566 }
567567
568568 public static function save_settings ( $ site_ID ) {
569-
570- $ _POST ['site_url ' ] = str_replace ( '/xmlrpc.php ' , '' , $ _POST ['site_url ' ] );
571-
572- update_post_meta ( $ site_ID , 'syn_site_url ' , esc_url_raw ( $ _POST ['site_url ' ] ) );
573- update_post_meta ( $ site_ID , 'syn_site_username ' , sanitize_text_field ( $ _POST ['site_username ' ] ) );
574- update_post_meta ( $ site_ID , 'syn_site_password ' , push_syndicate_encrypt ( sanitize_text_field ( $ _POST ['site_password ' ] ) ) );
575-
576- if ( !filter_var ( $ _POST ['site_url ' ], FILTER_VALIDATE_URL ) ) {
577- add_filter ('redirect_post_location ' , function ($ location ) {
578- return add_query_arg ("message " , 301 , $ location );
579- });
569+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- URL sanitized with esc_url_raw below.
570+ $ site_url = isset ( $ _POST ['site_url ' ] ) ? str_replace ( '/xmlrpc.php ' , '' , wp_unslash ( $ _POST ['site_url ' ] ) ) : '' ;
571+ $ username = isset ( $ _POST ['site_username ' ] ) ? sanitize_text_field ( wp_unslash ( $ _POST ['site_username ' ] ) ) : '' ;
572+
573+ // Use wp_strip_all_tags() for the password instead of sanitize_text_field()
574+ // because sanitize_text_field() converts encoded octets (e.g., %B2) which
575+ // can break passwords with special characters. The password is encrypted before storage anyway.
576+ // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- Password sanitized with wp_strip_all_tags.
577+ $ password = isset ( $ _POST ['site_password ' ] ) ? wp_strip_all_tags ( wp_unslash ( $ _POST ['site_password ' ] ) ) : '' ;
578+
579+ update_post_meta ( $ site_ID , 'syn_site_url ' , esc_url_raw ( $ site_url ) );
580+ update_post_meta ( $ site_ID , 'syn_site_username ' , $ username );
581+ update_post_meta ( $ site_ID , 'syn_site_password ' , push_syndicate_encrypt ( $ password ) );
582+
583+ if ( ! filter_var ( $ site_url , FILTER_VALIDATE_URL ) ) {
584+ add_filter (
585+ 'redirect_post_location ' ,
586+ function ( $ location ) {
587+ return add_query_arg ( 'message ' , 301 , $ location );
588+ }
589+ );
580590 return false ;
581591 }
582592
583593 return true ;
584-
585594 }
586595
587596 public function get_post ( $ ext_ID )
0 commit comments