From 2d4d22f3dee532689e0a1b6b027f33da3b5fe984 Mon Sep 17 00:00:00 2001 From: corsac Date: Wed, 21 Oct 2026 12:21:13 +0100 Subject: [PATCH] avoid overwriting contact methods on meta key collisions New contact method values get a key with a 3 character random hash (4096 possibilities) and nothing checked whether the key was in use, so adding a value could silently overwrite an existing one. Generate a new hash until the key is free. This also caused the intermittent test_overwrite_existing_fields_update failure. --- dt-posts/posts.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dt-posts/posts.php b/dt-posts/posts.php index 8c4f12694..002203bb3 100644 --- a/dt-posts/posts.php +++ b/dt-posts/posts.php @@ -2535,7 +2535,10 @@ public static function add_post_contact_method( array $post_settings, int $post_ $new_meta_key = ''; //check if this is a new field and is in the channel list if ( isset( $post_settings['fields'][ $field_key ] ) ) { - $new_meta_key = self::create_channel_metakey( $type, 'contact' ); + // The 3 character hash can repeat, and reusing a key would overwrite an existing value. + do { + $new_meta_key = self::create_channel_metakey( $type, 'contact' ); + } while ( metadata_exists( 'post', $post_id, $new_meta_key ) ); } update_post_meta( $post_id, $new_meta_key, $value ); $details = [ 'verified' => false ];