get_all() as $config ) { if ( (string) ( $config['host'] ?? '' ) === $host ) { return true; } } return false; } /** * Verify a fetched CIMD document against the trusted-publisher allowlist. * Returns the publisher slug on success, empty string on failure. * * @param string $client_id The URL the document was fetched from. * @param array $doc The decoded, URL-shape-validated metadata document. * @return string Publisher slug (e.g. 'claude') or '' if untrusted. */ public function verify( string $client_id, array $doc ): string { foreach ( $this->get_all() as $slug => $config ) { if ( $this->matches_publisher( $client_id, $doc, $config ) ) { return (string) $slug; } } return ''; } /** * Filtered trusted-publisher allowlist. Each entry MUST have: * - client_ids (string[]): exact URLs trusted for this publisher. * - host (string): hostname client_ids must resolve to (SSRF gate). * * @return array, host: string}> */ public function get_all(): array { $publishers = array( 'claude' => array( 'client_ids' => array( 'https://claude.ai/oauth/claude-code-client-metadata', 'https://claude.ai/oauth/mcp-oauth-client-metadata', ), 'host' => 'claude.ai', ), ); /** * Filter the CIMD trusted-publisher allowlist. * * This filter runs server-side with no request-derived input. It can * only ADD publishers; it cannot bypass the exact-client_id match or * the redirect_uri byte-match that AuthorizationController performs. * * @param array, host: string}> $publishers * @return array, host: string}> * @since 0.6.0 */ $filtered = apply_filters( 'acrossai_mcp_manager_cimd_trusted_publishers', $publishers ); return is_array( $filtered ) ? $filtered : $publishers; } /** * @param string $client_id * @param array $doc * @param array $config */ private function matches_publisher( string $client_id, array $doc, array $config ): bool { $client_ids = (array) ( $config['client_ids'] ?? array() ); // 1. Exact client_id must be in the pinned list (primary trust anchor). if ( ! in_array( $client_id, $client_ids, true ) ) { return false; } // 2. Host must match the publisher's host (defense in depth). $host = (string) wp_parse_url( $client_id, PHP_URL_HOST ); if ( '' === $host || (string) ( $config['host'] ?? '' ) !== $host ) { return false; } // 3. Public-client flow only. Redirect URI byte-match happens in // AuthorizationController::assert_redirect_uri_or_die — pinning it // here would break verification when a publisher registers extra // redirect_uris for sibling products. $auth_method = (string) ( $doc['token_endpoint_auth_method'] ?? 'none' ); return 'none' === $auth_method; } }