Below is a differential between the unpatched vulnerable code and the patched update, for reference.
--- a/ai-engine/ai-engine.php
+++ b/ai-engine/ai-engine.php
@@ -4,7 +4,7 @@
Plugin Name: AI Engine
Plugin URI: https://wordpress.org/plugins/ai-engine/
Description: AI meets WordPress. Your site can now chat, write poetry, solve problems, and maybe make you coffee.
-Version: 3.9.1
+Version: 3.9.2
Requires at least: 6.0
Requires PHP: 8.1
Author: Jordy Meow
@@ -24,7 +24,7 @@
return;
}
-define( 'MWAI_VERSION', '3.9.1' );
+define( 'MWAI_VERSION', '3.9.2' );
define( 'MWAI_PREFIX', 'mwai' );
define( 'MWAI_DOMAIN', 'ai-engine' );
define( 'MWAI_ENTRY', __FILE__ );
--- a/ai-engine/classes/admin.php
+++ b/ai-engine/classes/admin.php
@@ -465,6 +465,10 @@
'api_url' => get_rest_url( null, 'mwai/v1' ),
'rest_url' => get_rest_url(),
'home_url' => home_url(),
+ // Cloudflare adds CF-Ray to every request it proxies. Its bot challenge is the most common
+ // reason Claude or ChatGPT cannot connect, and the Connection Test, run from the site itself,
+ // often bypasses Cloudflare, so the MCP tab shows a hint whenever the site is behind it.
+ 'behind_cloudflare' => !empty( $_SERVER['HTTP_CF_RAY'] ),
'plugin_url' => MWAI_URL,
'user_data' => $this->core->get_user_data(),
'prefix' => MWAI_PREFIX,
--- a/ai-engine/classes/engines/openai.php
+++ b/ai-engine/classes/engines/openai.php
@@ -823,7 +823,64 @@
$endpoint = 'https://' . $endpoint;
}
- return $endpoint;
+ // Users often paste a full API address (from Azure's portal or a curl example) instead of the
+ // resource URL; every path below is built from the resource URL, so keep only that part.
+ $endpoint = preg_replace( '/?.*$/', '', $endpoint );
+ $endpoint = preg_replace( '#/openai/deployments/[^/]+/(chat/completions|embeddings|images/(generations|edits))$#', '', $endpoint );
+ $endpoint = preg_replace( '#/openai(/v1)?(/(responses|files))?$#', '', $endpoint );
+ $endpoint = preg_replace( '#/chat/completions$#', '', $endpoint );
+
+ return rtrim( $endpoint, '/' );
+ }
+
+ /**
+ * Azure has its own Files API address and key header. The shared upload_file() always posted to
+ * api.openai.com, so every document a chatbot sent on an Azure environment failed to upload
+ * (reported with a patch by Sumitomo Chemical, HS 3506730280). Azure also refuses the user_data
+ * purpose: files given to a model there use "assistants".
+ */
+ public function upload_file( $filename, $data, $purpose = 'fine-tune' ) {
+ if ( $this->envType !== 'azure' ) {
+ return parent::upload_file( $filename, $data, $purpose );
+ }
+ if ( $purpose === 'user_data' ) {
+ $purpose = 'assistants';
+ }
+ $boundary = wp_generate_password( 24, false );
+ $body = "--$boundaryrn";
+ $body .= "Content-Disposition: form-data; name="purpose"rnrn";
+ $body .= $purpose . "rn";
+ $body .= "--$boundaryrn";
+ $body .= "Content-Disposition: form-data; name="file"; filename="{$filename}"rn";
+ $body .= "Content-Type: application/octet-streamrnrn";
+ $body .= $data . "rn";
+ $body .= "--$boundary--rn";
+
+ // Same as the parent: streaming hooks on http_api_curl break a multipart upload.
+ global $wp_filter;
+ $saved_hooks = $wp_filter['http_api_curl'] ?? null;
+ unset( $wp_filter['http_api_curl'] );
+ $response = wp_remote_post( $this->build_azure_v1_url( $this->get_azure_endpoint(), '/files' ), [
+ 'headers' => [
+ 'api-key' => $this->apiKey,
+ 'Content-Type' => 'multipart/form-data; boundary=' . $boundary,
+ ],
+ 'body' => $body,
+ 'timeout' => 60,
+ 'sslverify' => MWAI_SSL_VERIFY,
+ ] );
+ if ( $saved_hooks !== null ) {
+ $wp_filter['http_api_curl'] = $saved_hooks;
+ }
+ if ( is_wp_error( $response ) ) {
+ throw new Exception( 'File upload failed: ' . $response->get_error_message() );
+ }
+ $decoded = json_decode( wp_remote_retrieve_body( $response ), true );
+ if ( wp_remote_retrieve_response_code( $response ) >= 400 ) {
+ $message = $decoded['error']['message'] ?? wp_remote_retrieve_body( $response );
+ throw new Exception( 'Azure file upload failed: ' . $message );
+ }
+ return $decoded;
}
/**
@@ -2887,6 +2944,12 @@
continue;
}
+ // Azure's Responses API reads only PDFs from uploaded files; Word, Excel and other
+ // documents need Code Interpreter there. Say so instead of failing later with a 400.
+ if ( $this->envType === 'azure' && $mimeType !== 'application/pdf' && $file->get_type() !== 'provider_file_id' ) {
+ throw new Exception( sprintf( 'The file %s cannot be sent to Azure OpenAI: Azure only accepts PDF documents here (and images).', $file->get_filename() ) );
+ }
+
if ( $file->get_type() !== 'provider_file_id' ) {
// File hasn't been uploaded to OpenAI yet - upload it now
try {
--- a/ai-engine/classes/modules/files.php
+++ b/ai-engine/classes/modules/files.php
@@ -378,6 +378,36 @@
return $refId;
}
+ /**
+ * The type a file's CONTENT supports, as [ 'ext' => ..., 'type' => ... ], or null when it does not
+ * match its name. Checking the name alone let HTML named x.flac be stored in the public uploads
+ * folder, where servers that don't map .flac serve it untyped and browsers run it (stored XSS,
+ * Patchstack 38706). WordPress already compares the content with the extension; it only rejects
+ * real audio whose detected type is a variant it doesn't list (audio/x-m4a for .m4a...), so those
+ * pass when finfo sees audio or video.
+ */
+ public function check_file_content( $path, $filename ) {
+ require_once( ABSPATH . 'wp-admin/includes/file.php' );
+ $check = wp_check_filetype_and_ext( $path, $filename );
+ if ( !empty( $check['type'] ) ) {
+ return [ 'ext' => $check['ext'], 'type' => $check['type'] ];
+ }
+ $ext = strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
+ if ( !in_array( $ext, [ 'flac', 'm4a', 'mp3', 'mp4', 'mpeg', 'mpga', 'oga', 'ogg', 'wav', 'webm' ], true ) ) {
+ return null;
+ }
+ $realMime = '';
+ if ( function_exists( 'finfo_open' ) ) {
+ $finfo = finfo_open( FILEINFO_MIME_TYPE );
+ $realMime = $finfo ? (string) finfo_file( $finfo, $path ) : '';
+ if ( $finfo ) {
+ finfo_close( $finfo );
+ }
+ }
+ $isMedia = strpos( $realMime, 'audio/' ) === 0 || strpos( $realMime, 'video/' ) === 0 || $realMime === 'application/ogg';
+ return $isMedia ? [ 'ext' => $ext, 'type' => 'audio/' . $ext ] : null;
+ }
+
public function upload_file(
$path,
$filename = null,
@@ -436,6 +466,12 @@
if ( !copy( $path, $destination ) ) {
throw new Exception( 'Could not move the file.' );
}
+ // Checked on the stored copy, so every caller is covered (chat and form uploads, the Public
+ // API, generated images that arrive as a URL). The library target is checked by WordPress.
+ if ( !$this->check_file_content( $destination, $filename ) ) {
+ wp_delete_file( $destination );
+ throw new Exception( 'File type is not allowed.' );
+ }
$url = wp_upload_dir()['url'] . '/' . $unique_filename;
$now = date( 'Y-m-d H:i:s' );
@@ -872,31 +908,15 @@
];
return new WP_REST_Response( [ 'success' => false, 'message' => $reasons[ $upload_error ] ?? 'The upload failed.' ], 400 );
}
- $purpose = empty( $_POST['purpose'] ) ? null : $_POST['purpose'];
+ $purpose = empty( $_POST['purpose'] ) ? null : sanitize_text_field( wp_unslash( $_POST['purpose'] ) );
$metadata = empty( $_POST['metadata'] ) ? null : json_decode( $_POST['metadata'], true );
- $envId = empty( $_POST['envId'] ) ? null : $_POST['envId'];
+ $envId = empty( $_POST['envId'] ) ? null : sanitize_text_field( wp_unslash( $_POST['envId'] ) );
if ( !$purpose ) {
return new WP_REST_Response( [ 'success' => false, 'message' => 'Purpose is required.' ], 400 );
}
- // Validate file type - allow audio files for transcription purpose
- $fileTypeCheck = wp_check_filetype_and_ext( $file['tmp_name'], $file['name'] );
-
- // If WordPress doesn't recognize the type, check if it's an audio file for transcription
- if ( !$fileTypeCheck['type'] ) {
- // Get file extension
- $ext = strtolower( pathinfo( $file['name'], PATHINFO_EXTENSION ) );
-
- // Whisper supported formats: flac, m4a, mp3, mp4, mpeg, mpga, oga, ogg, wav, webm
- $audioExtensions = [ 'flac', 'm4a', 'mp3', 'mp4', 'mpeg', 'mpga', 'oga', 'ogg', 'wav', 'webm' ];
-
- if ( in_array( $ext, $audioExtensions ) ) {
- // This is a valid audio file for transcription - override the type check
- $fileTypeCheck['type'] = 'audio/' . $ext;
- $fileTypeCheck['ext'] = $ext;
- }
- else {
- return new WP_REST_Response( [ 'success' => false, 'message' => 'Invalid file type.' ], 400 );
- }
+ // The same content check upload_file() runs, early, so a refused file costs nothing.
+ if ( !$this->check_file_content( $file['tmp_name'], $file['name'] ) ) {
+ return new WP_REST_Response( [ 'success' => false, 'message' => 'Invalid file type.' ], 400 );
}
// Guests can upload wherever a chatbot or form is shown, so cap them per visitor per hour,
--- a/ai-engine/labs/mcp-oauth.php
+++ b/ai-engine/labs/mcp-oauth.php
@@ -100,6 +100,14 @@
}
$this->emit_json( $this->authorization_server_metadata() );
}
+ // Only the form carrying our own issuer path: a bare /.well-known/openid-configuration may
+ // belong to an SSO or OpenID provider plugin on the site, and answering it would break it.
+ if ( strpos( $path, '/.well-known/openid-configuration/' ) === 0 && strpos( $path, '/' . $this->namespace ) !== false ) {
+ if ( $this->logging ) {
+ error_log( '[AI Engine MCP OAuth] Host-root OIDC hit: ' . $path );
+ }
+ $this->emit_json( $this->openid_configuration() );
+ }
}
/**
@@ -267,6 +275,22 @@
'permission_callback' => '__return_true',
] );
+ // OpenID Connect Discovery, appended to the issuer path. Claude tries the host-root
+ // /.well-known/ forms first, then this one. Managed hosts like SiteGround serve their own
+ // 404 for anything under the host-root /.well-known/ and never reach WordPress, so without
+ // this route Claude found no metadata and failed with "Couldn't register with ... sign-in
+ // service" (HS 3506632298, 2026-11-06). The nested path does reach WordPress there.
+ register_rest_route( $this->namespace, '/.well-known/openid-configuration', [
+ 'methods' => 'GET',
+ 'callback' => [ $this, 'handle_openid_configuration' ],
+ 'permission_callback' => '__return_true',
+ ] );
+ register_rest_route( $this->namespace, '/oauth/jwks', [
+ 'methods' => 'GET',
+ 'callback' => [ $this, 'handle_jwks' ],
+ 'permission_callback' => '__return_true',
+ ] );
+
// RFC 7591 — Dynamic Client Registration
register_rest_route( $this->namespace, '/oauth/register', [
'methods' => 'POST',
@@ -332,6 +356,25 @@
public function handle_as_metadata() {
return new WP_REST_Response( $this->authorization_server_metadata(), 200 );
}
+
+ public function handle_openid_configuration() {
+ return new WP_REST_Response( $this->openid_configuration(), 200 );
+ }
+
+ // No ID tokens are issued (the mcp scope is plain OAuth), so there are no keys to publish.
+ public function handle_jwks() {
+ return new WP_REST_Response( [ 'keys' => [] ], 200 );
+ }
+
+ // The OAuth metadata plus the fields OIDC discovery documents must carry, so clients that
+ // validate this URL strictly against the OpenID schema still accept it.
+ private function openid_configuration() {
+ return array_merge( $this->authorization_server_metadata(), [
+ 'jwks_uri' => rest_url( $this->namespace . '/oauth/jwks' ),
+ 'subject_types_supported' => [ 'public' ],
+ 'id_token_signing_alg_values_supported' => [ 'RS256' ],
+ ] );
+ }
#endregion
#region Dynamic Client Registration (RFC 7591)