@@ -237,11 +237,15 @@ public static function show_user_profile( $user ) {
237237 * @return void|never
238238 */
239239 public static function catch_submission ( $ user_id ) {
240- if ( ! empty ( $ _REQUEST ['do_new_security_key ' ] ) ) {
240+ if ( ! empty ( $ _REQUEST ['do_new_security_key ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce is verified immediately below.
241241 check_admin_referer ( "user_security_keys- {$ user_id }" , '_nonce_user_security_keys ' );
242242
243+ if ( ! isset ( $ _POST ['u2f_response ' ] ) ) {
244+ return ;
245+ }
246+
243247 try {
244- $ response = json_decode ( stripslashes ( $ _POST ['u2f_response ' ] ) );
248+ $ response = json_decode ( wp_unslash ( $ _POST ['u2f_response ' ] ) ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized -- JSON data decoded immediately.
245249 $ reg = Two_Factor_FIDO_U2F::$ u2f ->doRegister ( get_user_meta ( $ user_id , self ::REGISTER_DATA_USER_META_KEY , true ), $ response );
246250 $ reg ->new = true ;
247251
@@ -277,8 +281,8 @@ public static function catch_submission( $user_id ) {
277281 public static function catch_delete_security_key () {
278282 $ user_id = Two_Factor_Core::current_user_being_edited ();
279283
280- if ( ! empty ( $ user_id ) && ! empty ( $ _REQUEST ['delete_security_key ' ] ) ) {
281- $ slug = $ _REQUEST ['delete_security_key ' ];
284+ if ( ! empty ( $ user_id ) && ! empty ( $ _REQUEST ['delete_security_key ' ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce requires the slug value, verified immediately below.
285+ $ slug = sanitize_text_field ( wp_unslash ( $ _REQUEST ['delete_security_key ' ] ) ) ;
282286
283287 check_admin_referer ( "delete_security_key- {$ slug }" , '_nonce_delete_security_key ' );
284288
@@ -297,10 +301,10 @@ public static function catch_delete_security_key() {
297301 * @access public
298302 * @static
299303 *
300- * @param array $item The current item.
304+ * @param object $item The current item.
301305 * @return string
302306 */
303- public static function rename_link ( $ item ) {
307+ public static function rename_link ( $ item ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Required by WP_List_Table column callback interface.
304308 return sprintf ( '<a href="#" class="editinline">%s</a> ' , esc_html__ ( 'Rename ' , 'two-factor ' ) );
305309 }
306310
@@ -312,7 +316,7 @@ public static function rename_link( $item ) {
312316 * @access public
313317 * @static
314318 *
315- * @param array $item The current item.
319+ * @param object $item The current item.
316320 * @return string
317321 */
318322 public static function delete_link ( $ item ) {
@@ -345,13 +349,23 @@ public static function wp_ajax_inline_save() {
345349 wp_die ();
346350 }
347351
348- foreach ( $ security_keys as &$ key ) {
349- if ( $ key ->keyHandle === $ _POST ['keyHandle ' ] ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
352+ $ key = null ;
353+ foreach ( $ security_keys as $ security_key ) {
354+ if ( $ security_key ->keyHandle === $ _POST ['keyHandle ' ] ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
355+ $ key = $ security_key ;
350356 break ;
351357 }
352358 }
353359
354- $ key ->name = $ _POST ['name ' ];
360+ if ( ! $ key ) {
361+ wp_die ();
362+ }
363+
364+ if ( ! isset ( $ _POST ['name ' ] ) ) {
365+ wp_die ();
366+ }
367+
368+ $ key ->name = sanitize_text_field ( wp_unslash ( $ _POST ['name ' ] ) );
355369
356370 $ updated = Two_Factor_FIDO_U2F::update_security_key ( $ user_id , $ key );
357371 if ( ! $ updated ) {
0 commit comments