> $tests * @return array> */ public function register(array $tests): array { $tests['direct'][self::TEST] = [ 'label' => __('Alpaca Bot: web_fetch pinning', 'alpaca-bot'), 'test' => [$this, 'webFetch'], ]; return $tests; } /** * The test's own answer, in the shape core renders (class-wp-site-health.php:170-180). * * The cURL question is asked for https, the stricter of the two schemes: a cURL built * without SSL carries an http fetch and not an https one, and a server that cannot fetch * https is worth saying so about even where http would still work. * * @return array{label: string, status: string, badge: array{label: string, color: string}, description: string, actions: string, test: string} */ public function webFetch(): array { $enabled = $this->store->get('toolkits.enabled', []); if (!is_array($enabled) || !in_array('web_fetch', $enabled, true)) { return self::result('good', __('Alpaca Bot\'s web_fetch tool is switched off', 'alpaca-bot'), __('The model cannot fetch pages from this server, so there is nothing to pin.', 'alpaca-bot')); } if (!($this->curl ?? WebFetchToolkit::curlCarries(...))(true)) { return self::result('recommended', __('Alpaca Bot\'s web_fetch cannot run on this server', 'alpaca-bot'), __('web_fetch connects only to an address its check passed, and only cURL can be held to that. WordPress would send the request without cURL here, so web_fetch refuses every fetch. Ask your host for PHP\'s cURL extension with SSL, or switch web_fetch off under Alpaca Bot › Settings › Tools.', 'alpaca-bot')); } if (($this->proxied ?? static fn(): bool => (new \WP_HTTP_Proxy())->is_enabled())()) { return self::result('recommended', __('Alpaca Bot\'s web_fetch goes through a proxy that looks names up itself', 'alpaca-bot'), __('WP_PROXY_HOST and WP_PROXY_PORT are set, so WordPress hands a request to the proxy with the host name and the proxy resolves it. This site\'s own host, localhost and anything in WP_PROXY_BYPASS_HOSTS are not proxied. For the hosts that are, the address web_fetch checked is not the one the proxy connects to. What the proxy may reach, web_fetch may reach: restrict the proxy from private ranges and the cloud metadata address.', 'alpaca-bot')); } return self::result('good', __('Alpaca Bot\'s web_fetch connects only to addresses it checked', 'alpaca-bot'), __('A page web_fetch reads is looked up once, checked, and fetched through cURL from an address that passed and from no other, and so is each redirect it follows. The exception is this site\'s own host, which WordPress exempts from the address check and which web_fetch does not pin either, so whatever else answers on it stays reachable.', 'alpaca-bot')); } /** @return array{label: string, status: string, badge: array{label: string, color: string}, description: string, actions: string, test: string} */ private static function result(string $status, string $label, string $description): array { return [ 'label' => $label, 'status' => $status, 'badge' => ['label' => __('Security', 'alpaca-bot'), 'color' => 'blue'], 'description' => '

' . esc_html($description) . '

', 'actions' => '', 'test' => self::TEST, ]; } }