Make WordPress Core


Ignore:
Timestamp:
08/26/2026 11:48:53 AM (2 months ago)
Author:
gziolo
Message:

Connectors: Only validate submitted AI provider API keys

_wp_connectors_rest_settings_dispatch() validated every stored AI provider API key on each /wp/v2/settings update, because the response always contains the full set of registered settings. Saving an unrelated setting therefore triggered a live validation request to each configured provider, and a key that failed validation at that moment was silently reset.

Validate a key only when it is present in the current request, using WP_REST_Request::has_param(). Masking of stored keys in the response is unchanged.

Add test coverage for omitted, submitted-invalid, and submitted-valid keys to the existing Tests_Connectors_WpConnectorsRestSettingsDispatch suite.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/12350

Props khokansardar, hbhalodia, gziolo.
Fixes #65554. See #65867.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/connectors.php

    r62684 r63348  
    732732                $value = $data[ $setting_name ];
    733733
    734                 // On update, validate AI provider keys before masking.
     734                // On update, validate AI provider keys submitted in the request before masking.
    735735                // Non-AI connectors accept keys as-is; the service plugin handles its own validation.
    736                 if ( $is_update && is_string( $value ) && '' !== $value && 'ai_provider' === $connector_data['type'] ) {
     736                if ( $is_update
     737                        && $request->has_param( $setting_name )
     738                        && is_string( $value ) && '' !== $value
     739                        && 'ai_provider' === $connector_data['type']
     740                ) {
    737741                        if ( true !== _wp_connectors_is_ai_api_key_valid( $value, $connector_id ) ) {
    738742                                update_option( $setting_name, '' );
Note: See TracChangeset for help on using the changeset viewer.