PluginProbe
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN / 1.3.2
xSpeed Cache: AI-Powered Performance Hub with MCP, Caching & CDN v1.3.2
1.3.5 1.3.4 1.3.3 1.3.2 1.3.1 1.3.0 1.2.4 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 All 31 releases
← All changes | includes/modules/Mcp/Mcp_Server.php +41 -4 1.1.3 → 1.3.2 View file →
@@ -224,20 +224,26 @@
224 224 }
225 225
226 226 // Path 1: the static per-site pairing token (Mcp_Pairing). Leave the
227 227 // tool scope override cleared so Mcp_Tools defers to the pairing
228 - // token's own read-only scope.
228 + // token's own read-only scope. Credential writes over the pairing token
229 + // stay gated on the xspeed_mcp_allow_credential_writes filter (off by
230 + // default) — clear the configure override so that default applies. (#116)
229 231 $stored = Mcp_Pairing::site_token();
230 232 if ( '' !== $stored && hash_equals( $stored, $presented ) ) {
231 233 Mcp_Tools::set_read_only_override( null );
234 + Mcp_Tools::set_configure_override( null );
232 235 return true;
233 236 }
234 237
235 238 // Path 2: an OAuth 2.1 access token minted by Mcp_OAuth. Its own
236 - // granted scope decides read-only, independent of any pairing token.
239 + // granted scope decides read-only AND whether it may write credentials
240 + // (the explicit, opt-in `configure` scope), independent of any pairing
241 + // token.
237 242 $grant = Mcp_OAuth::validate_token( $presented );
238 243 if ( null !== $grant ) {
239 244 Mcp_Tools::set_read_only_override( Mcp_OAuth::scope_is_read_only( $grant['scope'] ) );
245 + Mcp_Tools::set_configure_override( Mcp_OAuth::scope_allows_configure( $grant['scope'] ) );
240 246 return true;
241 247 }
242 248
243 249 return false;
@@ -248,10 +254,41 @@
248 254 * this site's protected-resource metadata so an OAuth-capable client
249 255 * can discover the authorization server and begin the flow.
250 256 */
251 257 private static function challenge_header(): string {
252 - $metadata_url = home_url( '/.well-known/oauth-protected-resource' );
253 - return sprintf( 'Bearer resource_metadata="%s"', $metadata_url );
258 + return sprintf( 'Bearer resource_metadata="%s"', self::metadata_url() );
259 + }
260 +
261 + /**
262 + * Where this site actually serves its protected-resource metadata.
263 + *
264 + * Prefers the canonical /.well-known/ URL, but many hosts own that prefix
265 + * for ACME/Let's Encrypt and answer it before WordPress runs — the client
266 + * then follows a pointer to a 404 (or a redirect to the homepage) and the
267 + * OAuth flow dead-ends. RFC 9728 allows a single resource_metadata value,
268 + * so when the pretty path is not ours to serve we advertise the /wp-json
269 + * fallback, which no ACME tooling claims.
270 + */
271 + private static function metadata_url(): string {
272 + $pretty = home_url( '/.well-known/oauth-protected-resource' );
273 +
274 + /**
275 + * Filter the advertised protected-resource metadata URL.
276 + *
277 + * @param string $pretty The canonical /.well-known/ URL.
278 + */
279 + $filtered = apply_filters( 'xspeed_mcp_resource_metadata_url', $pretty );
280 + if ( is_string( $filtered ) && '' !== $filtered && $filtered !== $pretty ) {
281 + return $filtered;
282 + }
283 +
284 + // Rewrites absent (plain permalinks, or a flush that never landed)
285 + // means the pretty URL cannot resolve at all — use the fallback.
286 + if ( ! McpModule::wellknown_rewrites_active() ) {
287 + return rest_url( McpModule::NS . '/mcp/.well-known/oauth-protected-resource' );
288 + }
289 +
290 + return $pretty;
254 291 }
255 292
256 293 /** Pull the token from Bearer or X-XSpeed-MCP-Token, Bearer wins. */
257 294 private static function extract_token( \WP_REST_Request $request ): string {