From b260cc5604add30ed960277f19fbf2a6418bf76d Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 13 Sep 2026 15:17:43 +0200 Subject: [PATCH] fix(wordpress): accept MCP requests under the internal service name A client reaches the MCP endpoint by the provider's service name on the container network, so the hop is plain HTTP. WordPress hands out an application password only over SSL and, on an onion deployment, home_url() is http://, so the gate stays shut: core never even attempts to validate the credential and answers rest_not_logged_in. The client learns nothing about why. Measured on a live deployment, same credential, same endpoint, the only difference being the declaration of the scheme: 401 without it, 200 with it. Deliberately wrong passwords produced the same rest_not_logged_in as correct ones, which is what "never validated" looks like from outside. The accommodation belongs on the provider's side, as 5e810c4a5a already settled for Moodle: a probe that spoofs Host and X-Forwarded-Proto asserts the endpoint works when spoofed and says nothing about how a real client reaches it. That is exactly what happened here - the contract test sent the header and passed while hermes and openclaw, which send only their Authorization, were refused in run 34699757369 on both compose and swarm. WORDPRESS_INTERNAL_HOST is rendered from the same mcp.endpoint.service_key the clients build their URL from, so both sides name one thing once. The filter opens the gate for a request whose HTTP_HOST matches it, splits on ':' so a port cannot defeat the match, and changes nothing when the variable is unset. Its existing branches are untouched. contract.py loses the X-Forwarded-Proto it used to send. The test now takes the route a client takes, and can no longer be green while every client fails. Co-Authored-By: Claude Opus 5 (1M context) --- roles/test-e2e-cli/files/shared/mcp/contract.py | 1 - .../files/mu-plugins/infinito-mcp-abilities.php | 10 +++++++++- roles/web-app-wordpress/templates/env.j2 | 2 ++ roles/web-app-wordpress/vars/main.yml | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/roles/test-e2e-cli/files/shared/mcp/contract.py b/roles/test-e2e-cli/files/shared/mcp/contract.py index 8ac0a5f68d..4af0b34781 100644 --- a/roles/test-e2e-cli/files/shared/mcp/contract.py +++ b/roles/test-e2e-cli/files/shared/mcp/contract.py @@ -116,7 +116,6 @@ def rpc(method, params=None, authorization=None, url=None, notification=False): request.add_header("Accept", "application/json, text/event-stream") if HOST_HEADER: request.add_header("Host", HOST_HEADER) - request.add_header("X-Forwarded-Proto", "https") if authorization: request.add_header("Authorization", authorization) if SESSION["id"]: diff --git a/roles/web-app-wordpress/files/mu-plugins/infinito-mcp-abilities.php b/roles/web-app-wordpress/files/mu-plugins/infinito-mcp-abilities.php index 0c860548bc..c488bee87b 100644 --- a/roles/web-app-wordpress/files/mu-plugins/infinito-mcp-abilities.php +++ b/roles/web-app-wordpress/files/mu-plugins/infinito-mcp-abilities.php @@ -60,7 +60,15 @@ add_filter( 'rest_pre_dispatch', 'infinito_mcp_guard_transport', 10, 3 ); * @param bool $available Whether core already considers them available. */ function infinito_mcp_app_passwords_available( $available ) { - return $available || 'https' === wp_parse_url( home_url(), PHP_URL_SCHEME ); + if ( $available || 'https' === wp_parse_url( home_url(), PHP_URL_SCHEME ) ) { + return true; + } + $internal = getenv( 'WORDPRESS_INTERNAL_HOST' ); + if ( ! $internal ) { + return false; + } + $host = isset( $_SERVER['HTTP_HOST'] ) ? explode( ':', wp_unslash( $_SERVER['HTTP_HOST'] ) )[0] : ''; + return $host === $internal; } add_filter( 'wp_is_application_passwords_available', 'infinito_mcp_app_passwords_available' ); diff --git a/roles/web-app-wordpress/templates/env.j2 b/roles/web-app-wordpress/templates/env.j2 index 0393660ec8..057e6c5163 100644 --- a/roles/web-app-wordpress/templates/env.j2 +++ b/roles/web-app-wordpress/templates/env.j2 @@ -7,6 +7,8 @@ WORDPRESS_DB_NAME={{ lookup('database', application_id, 'name') }} WP_CLI_CACHE_DIR=/tmp/wp-cli-cache +WORDPRESS_INTERNAL_HOST={{ WORDPRESS_MCP_SERVICE_KEY }} + WP_DEBUG={{ MODE_DEBUG | lower }} WP_DEBUG_LOG={{ MODE_DEBUG | lower }} WP_DEBUG_DISPLAY={{ MODE_DEBUG | lower }} diff --git a/roles/web-app-wordpress/vars/main.yml b/roles/web-app-wordpress/vars/main.yml index cfe75648c2..52562c5cb8 100644 --- a/roles/web-app-wordpress/vars/main.yml +++ b/roles/web-app-wordpress/vars/main.yml @@ -22,6 +22,7 @@ WORDPRESS_USER: "www-data" WORDPRESS_LITELLM_ENV_ID: "{{ lookup('config', application_id, 'addons.ai-engine.config.environment.id') }}" WORDPRESS_MCP_ENABLED: "{{ lookup('config', application_id, 'mcp.enabled') }}" WORDPRESS_MCP_ADAPTER_VERSION: "{{ lookup('config', application_id, 'addons.mcp-adapter.version') }}" +WORDPRESS_MCP_SERVICE_KEY: "{{ lookup('config', application_id, 'mcp.endpoint.service_key') }}" WORDPRESS_MCP_ACCOUNT: "{{ lookup('users', 'mcp-web-app-wordpress') }}" WORDPRESS_MCP_USERNAME: "{{ WORDPRESS_MCP_ACCOUNT.username }}" WORDPRESS_MCP_EMAIL: "{{ WORDPRESS_MCP_ACCOUNT.email }}"