filtered( false, $url, '' ); } $literal = false !== filter_var( $host, FILTER_VALIDATE_IP ); $ip = $literal ? $host : gethostbyname( $host ); // gethostbyname() hands the hostname back unchanged when it cannot resolve. A destination that // does not resolve is not one to post a signed payload to. if ( ! $literal && $ip === $host ) { return $this->filtered( false, $url, '' ); } $public = filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ); return $this->filtered( false !== $public, $url, (string) $ip ); } /** * @param bool $allowed What the checks decided. * @param string $url The destination. * @param string $ip What the host resolved to, empty when it did not. */ private function filtered( bool $allowed, string $url, string $ip ): bool { /** * Filters whether an outbound destination is allowed. * * The escape hatch for a site whose integration genuinely lives on the same private network — * a staging box, an internal queue, a container on the same host. It is a filter rather than a * setting because a setting is a checkbox somebody ticks to make an error message go away, * without ever reading what the check was for. * * @param bool $allowed Whether the destination passed the checks. * @param string $url The destination. * @param string $ip What the host resolved to, empty when it did not resolve. */ $allowed = (bool) apply_filters( 'plugixa_crm_outbound_destination_allowed', $allowed, $url, $ip ); /** * Legacy name, kept because it is a public seam a site may already be using. * * Until this class moved into Core it guarded webhooks and nothing else, so this filter was * global in practice — a site that hooked it to reach a staging box was allowing every * outbound request the CRM made. Applying it last preserves that exactly, rather than * silently narrowing a hatch somebody is relying on. New code should hook the filter above. * * @param bool $allowed Whether the destination passed the checks. * @param string $url The destination. * @param string $ip What the host resolved to, empty when it did not resolve. */ return (bool) apply_filters( 'plugixa_crm_webhook_destination_allowed', $allowed, $url, $ip ); } }