�PNG  IHDR22?�� pHYs  �� OiCCPPhotoshop ICC profilexڝSgTS�=���BK���KoR RB���&*! J�!��Q�EEȠ�����Q, � ��!���������{�kּ������>���� �H3Q5� �B�������.@� $p�d!s�#�~<<+"��x� �M��0���B�\���t�8K�@z�B�@F���&S�`�cb�P-`'������{[�!�� e�Dh;��V�EX0fK�9�-0IWfH���� � 0Q��){`�##x��F�W<�+��*x��<�$9E�[-qWW.(�I+6aa�@.�y�2�4���������x����6��_-��"bb���ϫp@�t~��,/��;�m��%�h^ �u��f�@����W�p�~<�5�j>{�-�]c�K'Xt����o��(�h���w��?�G�%�fI�q^D$.Tʳ?�D��*�A��,���� �`6�B$��BB d�r`)��B(�Ͱ*`/�@4�Qh��p.�U�=p�a��(�� A�a!ڈb�X#����!�H�$ ɈQ"K�5H1R�T UH�=r9�\F��;�2����G1���Q=� �C��7�F� �dt1�����r�=�6��Ыhڏ>C�0��3�l0.��B�8, �c˱"� ���V����cϱw�E� 6wB aAHXLXN�H� $4� 7 �Q�'"��K�&���b21�XH,#��/{�C�7$�C2'��I��T��F�nR#�,��4H#���dk�9�, +ȅ����3��!�[ �b@q��S�(R�jJ��4�e�2AU��Rݨ�T5�ZB���R�Q��4u�9̓IK�����hh�i��t�ݕN��W���G���w ��Ljg(�gw��L�Ӌ�T071���oUX*�*|�� �J�&�*/T����ު U�U�T��^S}�FU3S� Ԗ�U��P�SSg�;���g�oT?�~Y��Y�L�OC�Q��_�� c�x,!k ��u�5�&���|v*�����=���9C3J3W�R�f?�q��tN �(���~���)�)�4L�1e\k����X�H�Q�G�6������E�Y��A�J'\'Gg����S�Sݧ �M=:��.�k���Dw�n��^��Lo��y���}/�T�m���G X� $� �<�5qo</���QC]�@C�a�a�ᄑ��<��F�F�i�\�$�m�mƣ&&!&KM�M�RM��)�;L;L���͢�֙5�=1�2��כ߷`ZxZ,����eI��Z�Yn�Z9Y�XUZ]�F���%ֻ�����N�N���gð�ɶ�����ۮ�m�}agbg�Ů��}�}��= ���Z~s�r:V:ޚΜ�?}����/gX���3��)�i�S��Ggg�s�󈋉K��.�>.���Ƚ�Jt�q]�z���������ۯ�6�i�ܟ�4�)�Y3s���C�Q��? ��0k߬~OCO�g��#/c/�W�װ��w��a�>�>r��>�<7�2�Y_�7��ȷ�O�o�_��C#�d�z����%g��A�[��z|!��?:�e����A���AA�������!h�쐭!��Α�i�P~���a�a��~ '���W�?�p�X�1�5w��Cs�D�D�Dޛg1O9�-J5*>�.j<�7�4�?�.fY��X�XIlK9.*�6nl������� �{�/�]py�����.,:�@L�N8��A*��%�w%� y��g"/�6ш�C\*N�H*Mz�쑼5y$�3�,幄'���L Lݛ:��v m2=:�1����qB�!M��g�g�fvˬe����n��/��k���Y- �B��TZ(�*�geWf�͉�9���+��̳�ې7�����ᒶ��KW-X潬j9�������(�x��oʿ�ܔ���Ĺd�f�f���-�[����n �ڴ �V����E�/��(ۻ��C���<��e����;?T�T�T�T6��ݵa��n��{��4���[���>ɾ�UUM�f�e�I���?�������m]�Nmq����#�׹���=TR��+�G�����w- 6 U����#pDy��� �� :�v�{���vg/jB��F�S��[b[�O�>����z�G��499�?r����C�d�&����ˮ/~�����јѡ�򗓿m|������������x31^�V���w�w��O�| (�h���SЧ��������c3-� cHRMz%������u0�`:�o�_�F5IDATx��ytUս�?�;���fN$$��@B�!�k��� -*�gE���j�O�kQ�ʠ`U�B_ �AÐ0%�Ȕ�@r3ޛ;߳��$�@��v����^�s����������$��ߢ !�W��5�̱'-٘������4�>�Rƫ$�G��0U�H}�_ _� #��k�MJ/=�9Du *ڲ�k�PQ;0��j|�*�$�^컂脛y���>�z×� B��� ��(�:$�ʔ_�6��C!B����MVx��a��ζyY����j��ƋY2�9�F�{r��r�딟F��Q��hY6��� x��[l��RC��������nt@��;P��3��� F�w��7��:�P���ɋ'���mj���Bƪ�$�Q�L��y��߷g��\���z����v5�p�v$�v櫻�`6~K �Y�X����,�:��"�o�e0II"(��,������l_�C���/4�+f�E�!q��:����u����c��樼.UE�@� �]K�W���$-�h]�JG���Dz)�`��.�A/ ���mᏣc�3jK� �!�>���$�Q�!�_�? \�C2(E �M$Z I{�U���s�ǣ���=��@Բe ޻��W�����@ �w����}�9v,)��.}*|"�s��di���,���G�]W�AC�������|<����[��ߕ������K�*�G nߴ!��‹��J�!��6(L�a)��Am��������;adf��:�xm��nh�;֦I��(���o�C~ډa?�=��s����h��E������xp����)���_���t��W�����´;8���`dz=(��@@�+,�;�`�fhl��XȌ�3,uI�~z(J����� �ZX�A����H'�À�㜦�82|��a�n�z2��I���� ���EY�h�ε<�0�q�{��C��v�˅��?"@��χ�x�WS+��N�~�KQ�J�8ل�� _.W��� !TU{�����,��"�� �;�������HI S� ��))�o�1�H�D� ���� (� ;����"Ҕ��,���� �F=���O��&�Ph>�`���y��߲ &S��P�<��'��1s�1cĂ�N����2)����@�u��tv��<�+�-&�����h��[!FSG���' � z z0��<����8d&�����E0�,��<��"!P�b4��� �{S�����X����.�囤���T��hEF��X�q0"-<����h���]�Py*����F⩍��@v�˂�Y08�� .q��a��s����(!<̫1�3�L�H��7sYW�`��qtu�\7��?�@�Y�� %Ka�x�GZ�*W�P��y�����N0r9��Z�c�%���q,��k�����!!,��>���IB��� �x1�Xu�Y���v-���ֺ��N������JP��a�2`�e5��w��u;�6�i���̃��(K���ťa��(l51��JL��O'%���]���ٖ뿉!��{*�p+f ���i8��D�ȑ���ܩ�M��V��ӟz��x�7Z�1i}�^͜���6e����x��)u�d�ˏ�V�eG�\�X1�����=n�U'�~Y����L�\,�(d!x ,�:�TW8� M`r���@��r+v�Q0��>^;˴�VbF��('����� �*O��i��j�Ӆ����^�S3&� ���{������.ی�� N;��NU%d0�Ce\r"�C�b��&t7N�7��� �ȪD�[%l�۪�$��'m?�A9tI�9>��NVL ��� 6v~M�����ъ�B���0����9$&=ώm��W�0���L���&��E���f�f��'+�9��hv��7,���M��6�D�&�^� �����8 D֮�����o��k^z��O��hP�8q�5d*��YVq3�{��������#LX4�?��jP=3�~�؅c�ݰ�̱�ұ��8̲��2�G�����j��έ�9��w7���U�X�w�85C��?!I&���o&����L���I#�^�eV�,�^t5�k� �xs˛\��U�8��."���{���ǵ�l4��ݼ�;��r"���G�/~���gJV�N糦��ZZ^k+NN�D��I$�=OE�z����|*�*{��%k���G��>�`9��b;�s���8,�qs��c��.b��q�%�>r��n�R�Ƨ�%�,�A��le#�8���}; 21�0�b�&�QX�f���q�00����$>�h�N�'�a3��A���/�r ��L5�8�GԲ'�����w;��c#�q1���h$*��V^�k��QĽ�b:i������� ����H F#�_���,��]g����Ը����`RUU���� ��"�qD���>-��ϤI�~��3�̴�����NZ[[555�eeek7�m����YF#[��Đ��R��i��L�H�r ��@��J-�Pŝ��_|�-��6y��ks�V�U~��6���w.����(��0A� 4��f��� /���C�xŊ�ٳ����z=6�����rg���mKo��o�/����a�g���?'9%9��P��斓��~���L{�� �H��{AW��B��$����v�1b�&Mb�ر��ر#�0`�`xMBp! )Z�Nmo�mZ�g�}�eذaWTVV ���'99��C5��&�&+5�bT>|8��PUUETT����&���t��~TE%��'������b�tEGG;RSS�S�N�v��ѯ��t����u1@�ޚ"f��͈���r'L�Ph��m��ƌ�74o��`�x�q�P���NRSS�X,�����l&&&��MFFA!-��`��ҷ�n��Yuu�����x<I�LB%����KԒ50�!�3�bz�����ʸKL���;---�l6[��`��������Ȏ;�����egg4��!D�T��jWujyZ��������K����%����p�^���X,6��sV=�ܖ����6�3�X ���4ҿ��A2�&����_k�;d�� �VfOIEND�B`� 0x0x
PHP 8.1.34
Preview: MuLoader.php Size: 22.44 KB
/home2/astrociv/public_html/avitours.in/wp-content/plugins/imunify-security/inc/App/Bot/MuLoader.php
<?php
/**
 * Copyright (с) Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2025 All Rights Reserved
 *
 * Licensed under CLOUD LINUX LICENSE AGREEMENT
 * https://www.cloudlinux.com/legal/
 */

namespace CloudLinux\Imunify\App\Bot;

use CloudLinux\Imunify\App\AgentDataFile;
use CloudLinux\Imunify\App\Model\PluginConfig;

/**
 * Side-effecting bootstrap for the mu-plugin shim.
 *
 * Exposes two entry points:
 *   - run(): production entry. Reads WP_CONTENT_DIR + $_SERVER, builds
 *            a production Responder, defers to runWith().
 *   - runWith(): deterministic entry for tests. Takes the content dir,
 *                $_SERVER snapshot, and Responder as arguments so the
 *                whole wiring can be exercised under PHPUnit.
 *
 * Short-circuit order (cheapest / strongest first):
 *   1. Server gate — plugin_config.php::ai_bot_protection.
 *      Off or missing / malformed → pass through.
 *   2. Site-owner opt-out — IMUNIFY_AI_BOT_PROTECTION wp-config
 *      constant, default true per the parent epic. Defined and false
 *      → pass through.
 *   3. Site-owner opt-out — bot-settings.php::enabled (widget-written).
 *      False → pass through.
 *
 * Preset resolution (first match wins):
 *   a. IMUNIFY_AI_BOT_PROTECTION_PRESET constant (power user).
 *   b. bot-settings.php::preset if the site owner has explicitly
 *      picked one (widget).
 *   c. plugin_config.php::preset hoster default written by the agent.
 *   d. Preset::BALANCED.
 * Unknown values at any layer fall through to the next so an admin typo
 * never disables rate limiting or crashes the bootstrap.
 *
 * @since 4.0.0
 */
class MuLoader {

	/**
	 * Names of bot-ip-range providers treated as verified search engines.
	 *
	 * Kept here (not on IpRangeLookup) so the partition is trivially
	 * reviewable next to the pipeline wiring that uses it. Returned from
	 * a static method rather than an array-valued class constant because
	 * the latter is PHP 7.0+ syntax and the plugin must parse on PHP 5.6
	 * — an array `const` triggers a fatal parse error there, which the
	 * mu-plugin shim's runtime catch can never intercept.
	 *
	 * @return array
	 */
	private static function searchEngineProviders() {
		return array( 'google', 'bing', 'apple', 'duckduckgo', 'meta' );
	}

	/**
	 * Names of bot-ip-range providers treated as verified AI crawlers.
	 *
	 * See searchEngineProviders() for the reason this is a method
	 * rather than a class constant.
	 *
	 * @return array
	 */
	private static function aiCrawlerProviders() {
		return array( 'anthropic', 'openai', 'meta', 'perplexity', 'google', 'duckassistbot' );
	}

	/**
	 * Names of bot-ip-range providers treated as verified SEO crawlers.
	 *
	 * See searchEngineProviders() for the reason this is a method
	 * rather than a class constant.
	 *
	 * @return array
	 */
	private static function seoCrawlerProviders() {
		return array( 'ahrefs', 'barkrowler' );
	}

	/**
	 * Bot-ip-range providers that confirm a single ai-crawler token, mapped to
	 * that token. They never join the ai-crawler lookup, where any unmapped
	 * token would verify against them.
	 *
	 * See searchEngineProviders() for the reason this is a method
	 * rather than a class constant.
	 *
	 * @return array Provider name => ai-crawler token.
	 */
	private static function aiTokenScopedProviders() {
		return array( 'anthropic-outbound' => 'Claude-User' );
	}

	/**
	 * Split the bundled bot-ip-range providers into the search-engine and
	 * AI-crawler lookups the Classifier consumes.
	 *
	 * The two membership tests are independent rather than mutually
	 * exclusive: a provider that serves both roles must land in both lookups.
	 * Google ships Googlebot from the same ranges it uses for GoogleOther /
	 * Gemini, so 'google' belongs to both sets; the disjoint UA token lists
	 * (ua-search-engines vs ua-ai-crawlers) keep any single request on
	 * exactly one Classifier branch.
	 *
	 * @param array $providers Map of provider name => data-file path.
	 * @return array 'search_engines', 'ai_crawlers' and 'seo_crawlers', each a
	 *               provider-name => file map, and 'ai_token_scoped', a
	 *               lower-cased token => file map.
	 */
	private static function partitionBotIpRanges( $providers ) {
		$search_engines = array();
		$ai_crawlers    = array();
		$seo_crawlers   = array();
		$token_scoped   = array();
		$scoped_tokens  = self::aiTokenScopedProviders();
		foreach ( $providers as $name => $file ) {
			if ( in_array( $name, self::searchEngineProviders(), true ) ) {
				$search_engines[ $name ] = $file;
			}
			if ( in_array( $name, self::aiCrawlerProviders(), true ) ) {
				$ai_crawlers[ $name ] = $file;
			}
			if ( in_array( $name, self::seoCrawlerProviders(), true ) ) {
				$seo_crawlers[ $name ] = $file;
			}
			if ( isset( $scoped_tokens[ $name ] ) ) {
				$token_scoped[ strtolower( $scoped_tokens[ $name ] ) ] = $file;
			}
		}
		return array(
			'search_engines'  => $search_engines,
			'ai_crawlers'     => $ai_crawlers,
			'seo_crawlers'    => $seo_crawlers,
			'ai_token_scoped' => $token_scoped,
		);
	}

	/**
	 * Production entry point — the shim calls this.
	 *
	 * @return void
	 */
	public static function run() {
		if ( ! defined( 'WP_CONTENT_DIR' ) ) {
			return;
		}
		// The main plugin's autoloader isn't registered yet — we run at
		// muplugins_loaded, which is before the regular plugin file is
		// included. Register a minimal spl_autoload for the sibling
		// CloudLinux\Imunify\* classes we need so class resolution inside
		// the pipeline doesn't silently fail-open through the shim's
		// Throwable catch.
		self::registerAutoloader();
		BotLifecycle::registerCleanupHooks();
		if ( defined( 'WP_CLI' ) && WP_CLI ) {
			return;
		}
		self::runWith(
			(string) WP_CONTENT_DIR,
			$_SERVER,
			new Responder( false ),
			$_POST, // phpcs:ignore WordPress.Security.NonceVerification.Missing -- read-only: RestNamespaceMatcher compares rest_route with the one WordPress will route on.
			array( __CLASS__, 'siteRouting' )
		);
	}

	/**
	 * How WordPress routes requests on the current site.
	 *
	 * @since 4.1.4
	 *
	 * @return array 'pretty_permalinks', 'home_path' and 'site_path'.
	 */
	public static function siteRouting() {
		return array(
			'pretty_permalinks' => self::hasPrettyPermalinks(),
			'home_path'         => self::homePath(),
			'site_path'         => self::sitePath(),
		);
	}

	/**
	 * The allowlist rule the request pipeline would let a request through by, with the given
	 * site-owner entries in place of the saved ones. Nothing is recorded or answered.
	 *
	 * @since 4.1.4
	 *
	 * @param string        $wp_content_dir Absolute path to wp-content.
	 * @param array         $server         $_SERVER snapshot of the request.
	 * @param SiteAllowlist $site_allowlist The site owner's entries.
	 * @param array         $site           Routing, as siteRouting() returns it.
	 * @return AllowlistMatch|null
	 */
	public static function allowlistMatch( $wp_content_dir, $server, SiteAllowlist $site_allowlist, $site ) {
		$pipeline = self::buildPipeline(
			$wp_content_dir,
			Preset::DEFAULT_PRESET,
			new Responder( false ),
			false,
			isset( $server['SERVER_ADDR'] ) ? (string) $server['SERVER_ADDR'] : '',
			array(),
			! empty( $site['pretty_permalinks'] ),
			isset( $site['home_path'] ) && is_string( $site['home_path'] ) ? $site['home_path'] : null,
			isset( $site['site_path'] ) && is_string( $site['site_path'] ) ? $site['site_path'] : null,
			$site_allowlist
		);
		return $pipeline->allowlistMatch( $server );
	}

	/**
	 * Whether the site has a permalink structure; without one WordPress routes nothing by path.
	 *
	 * @return bool
	 */
	private static function hasPrettyPermalinks() {
		return function_exists( 'get_option' ) && '' !== (string) get_option( 'permalink_structure' );
	}

	/**
	 * Path of the filtered home URL, the base WP::parse_request() strips before routing.
	 *
	 * @return string|null '' on a root site, null when the home URL is unavailable.
	 */
	private static function homePath() {
		return function_exists( 'home_url' ) ? self::urlPath( home_url() ) : null;
	}

	/**
	 * Path of the site URL, the folder WordPress itself lives in.
	 *
	 * @since 4.1.4
	 *
	 * @return string|null '' when WordPress lives at the root, null when the site URL is unavailable.
	 */
	private static function sitePath() {
		return function_exists( 'site_url' ) ? self::urlPath( site_url() ) : null;
	}

	/**
	 * Path of a URL without a trailing slash.
	 *
	 * @since 4.1.4
	 *
	 * @param mixed $url URL.
	 * @return string|null Null for an empty or non-string URL.
	 */
	private static function urlPath( $url ) {
		if ( ! is_string( $url ) || '' === $url ) {
			return null;
		}
		// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url -- pre-WP hot path; wp_parse_url may not be available.
		return rtrim( (string) parse_url( $url, PHP_URL_PATH ), '/' );
	}

	/**
	 * Register a narrow PSR-0-ish autoloader rooted at this plugin's
	 * inc/ directory. Idempotent — safe to call on every request.
	 *
	 * @return void
	 */
	private static function registerAutoloader() {
		static $registered = false;
		if ( $registered ) {
			return;
		}
		$inc_dir = dirname( dirname( __DIR__ ) );
		spl_autoload_register(
			function ( $class ) use ( $inc_dir ) {
				$prefix = 'CloudLinux\\Imunify\\';
				if ( 0 !== strpos( $class, $prefix ) ) {
					return;
				}
				$relative = substr( $class, strlen( $prefix ) );
				$file     = $inc_dir . '/' . str_replace( '\\', '/', $relative ) . '.php';
				// @phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged
				if ( @is_readable( $file ) ) {
					include_once $file;
				}
			}
		);
		$registered = true;
	}

	/**
	 * Deterministic entry point exposed for tests.
	 *
	 * @since 4.1.3 Added $form_post and $routing.
	 * @since 4.1.4 $routing may return 'site_path'.
	 *
	 * @param string        $wp_content_dir Absolute path to wp-content.
	 * @param array         $server         $_SERVER snapshot.
	 * @param Responder     $responder      Response emitter.
	 * @param array         $form_post      $_POST snapshot.
	 * @param callable|null $routing        Returns 'pretty_permalinks', 'home_path' and 'site_path'; called after the gates pass.
	 * @return void
	 */
	public static function runWith( $wp_content_dir, $server, $responder, $form_post = array(), $routing = null ) {
		$gates = self::activeGates( $wp_content_dir );
		if ( null === $gates ) {
			return;
		}
		list( $cfg, $opt_out ) = $gates;

		$site = is_callable( $routing ) ? call_user_func( $routing ) : array();

		$pipeline = self::buildPipeline(
			$wp_content_dir,
			self::resolvePreset( $opt_out, $cfg ),
			$responder,
			$opt_out->isStatsEnabled(),
			isset( $server['SERVER_ADDR'] ) ? (string) $server['SERVER_ADDR'] : '',
			$form_post,
			! empty( $site['pretty_permalinks'] ),
			isset( $site['home_path'] ) && is_string( $site['home_path'] ) ? $site['home_path'] : null,
			isset( $site['site_path'] ) && is_string( $site['site_path'] ) ? $site['site_path'] : null
		);
		$pipeline->run( $server );
	}

	/**
	 * Whether requests to the site go through bot protection: the server, wp-config and the site owner all allow it.
	 *
	 * @since 4.1.4
	 *
	 * @param string $wp_content_dir Absolute path to wp-content.
	 * @return bool
	 */
	public static function isProtectionActive( $wp_content_dir ) {
		return null !== self::activeGates( $wp_content_dir );
	}

	/**
	 * The plugin config and the site owner's preference when every gate lets requests through, null otherwise.
	 *
	 * @since 4.1.4
	 *
	 * @param string $wp_content_dir Absolute path to wp-content.
	 * @return array|null array( PluginConfig, OptOutFlag ).
	 */
	private static function activeGates( $wp_content_dir ) {
		$cfg = self::loadPluginConfig( $wp_content_dir );
		if ( ! $cfg->isAiBotProtectionEnabled() || self::siteDisabledByConstant() ) {
			return null;
		}
		$opt_out = OptOutFlag::load( $wp_content_dir );
		return $opt_out->isEnabled() ? array( $cfg, $opt_out ) : null;
	}

	/**
	 * Site-owner opt-out via IMUNIFY_AI_BOT_PROTECTION wp-config constant.
	 *
	 * @return bool True iff the constant is defined and evaluates false.
	 */
	private static function siteDisabledByConstant() {
		return defined( 'IMUNIFY_AI_BOT_PROTECTION' )
			&& false === (bool) constant( 'IMUNIFY_AI_BOT_PROTECTION' );
	}

	/**
	 * Whether the current request is a WP-Cron run.
	 *
	 * WordPress's wp_doing_cron() layers the `wp_doing_cron` filter over the
	 * DOING_CRON constant; guarded with function_exists so the shim degrades to
	 * "not a cron run" when WP core's helper isn't loaded yet.
	 *
	 * @return bool
	 */
	private static function isDoingCron() {
		return function_exists( 'wp_doing_cron' ) && wp_doing_cron();
	}

	/**
	 * Optional override for the rate-limiter rolling window via a wp-config
	 * constant.  Returns null when the constant is not defined (so the
	 * RateLimiter falls back to its built-in WINDOW_SECONDS).
	 *
	 * @return int|null
	 */
	private static function resolveWindowSeconds() {
		if ( defined( 'IMUNIFY_RATE_LIMIT_WINDOW' ) ) {
			return (int) constant( 'IMUNIFY_RATE_LIMIT_WINDOW' );
		}
		return null;
	}

	/**
	 * Resolve the active preset via the shared chain in Preset::resolve().
	 *
	 * @param OptOutFlag   $opt_out Site-owner preference loaded by runWith().
	 * @param PluginConfig $cfg     Decoded plugin_config.php.
	 * @return string One of Preset::BALANCED/STRICT/MONITOR.
	 */
	private static function resolvePreset( $opt_out, PluginConfig $cfg ) {
		return Preset::resolve( $opt_out, $cfg );
	}

	/**
	 * Read plugin_config.php exactly once per request and return the
	 * resulting PluginConfig. Threaded through the gate check and
	 * preset resolution so the file isn't re-read on the hot path.
	 *
	 * Returns an indeterminate PluginConfig — rather than one that reads
	 * as cleanly disabled — when the file is missing, unreadable, or
	 * fails to parse, so MuPluginSelfHealer can tell "couldn't confirm
	 * the gate" apart from "hoster turned it off" instead of tearing
	 * down an already-installed shim on a transient read failure.
	 *
	 * @param string $wp_content_dir Absolute path to wp-content.
	 * @return PluginConfig
	 */
	public static function loadPluginConfig( $wp_content_dir ) {
		$path = rtrim( $wp_content_dir, '/' ) . '/imunify-security/plugin_config.php';
		clearstatcache( true );
		if ( ! is_readable( $path ) ) {
			return PluginConfig::indeterminate();
		}
		try {
			$raw = AgentDataFile::readEmbeddedJson( $path );
		} catch ( \UnexpectedValueException $e ) {
			return PluginConfig::indeterminate();
		}
		if ( ! is_array( $raw ) ) {
			return PluginConfig::indeterminate();
		}
		return PluginConfig::fromArray( $raw );
	}

	/**
	 * Optional override for the FCrDNS verifier's PTR / forward resolvers,
	 * supplied through the `imunify_security_bot_rdns_resolvers` filter.
	 *
	 * With no hook the filter returns the empty default, so production keeps
	 * RdnsVerifier's real dns_get_record resolvers. Hooking the filter
	 * requires code already running inside WordPress, which is the trust
	 * boundary the rest of the plugin assumes; it does not widen the
	 * attacker's reach.
	 *
	 * Malformed returns degrade safely: a non-array result yields no
	 * override, and a non-callable 'reverse'/'forward' is ignored by
	 * RdnsVerifier, which falls back to its dns_get_record default.
	 *
	 * @return array Map with optional 'reverse' / 'forward' callables.
	 */
	private static function rdnsResolverOverrides() {
		if ( ! function_exists( 'apply_filters' ) ) {
			return array();
		}
		$overrides = apply_filters( 'imunify_security_bot_rdns_resolvers', array() );
		return is_array( $overrides ) ? $overrides : array();
	}

	/**
	 * Build the production Pipeline over the bundled classifier data.
	 *
	 * @param string             $wp_content_dir Absolute path to wp-content.
	 * @param string             $preset         Preset identifier.
	 * @param Responder          $responder      Response emitter.
	 * @param bool               $stats_enabled  Whether to attach the hourly stats recorder.
	 * @param string             $server_addr    $_SERVER['SERVER_ADDR'] for this request.
	 * @param array              $form_post         $_POST snapshot for this request.
	 * @param bool               $pretty_permalinks Whether the site has a permalink structure.
	 * @param string|null        $home_path         Path of the home URL, null when unknown.
	 * @param string|null        $site_path         Path of the site URL, null when unknown.
	 * @param SiteAllowlist|null $site_allowlist    The site owner's entries; null reads bot-allowlist.php.
	 * @return Pipeline
	 */
	private static function buildPipeline( $wp_content_dir, $preset, $responder, $stats_enabled, $server_addr, $form_post = array(), $pretty_permalinks = false, $home_path = null, $site_path = null, $site_allowlist = null ) {
		$bundled_dir = self::pluginDir() . '/inc/App/Bot/data';
		$overlay_dir = self::overlayDir( $wp_content_dir );
		$bundled     = new BundledData( $bundled_dir, $overlay_dir );

		$partition      = self::partitionBotIpRanges( $bundled->providersIn( 'bot-ip-ranges' ) );
		$search_engines = $partition['search_engines'];
		$ai_crawlers    = $partition['ai_crawlers'];
		$seo_crawlers   = $partition['seo_crawlers'];

		$cdn = new CdnDetector(
			new IpRangeLookup( $bundled->providersIn( 'cdn-ip-ranges' ) )
		);

		$signatures = new UserAgentSignatures(
			array(
				UserAgentSignatures::CATEGORY_MALICIOUS   => $bundled->pathFor( 'signatures/ua-malicious.php' ),
				UserAgentSignatures::CATEGORY_SEARCH_ENGINE => $bundled->pathFor( 'signatures/ua-search-engines.php' ),
				UserAgentSignatures::CATEGORY_SEO_CRAWLER => $bundled->pathFor( 'signatures/ua-seo-crawlers.php' ),
				UserAgentSignatures::CATEGORY_AI_CRAWLER  => $bundled->pathFor( 'signatures/ua-ai-crawlers.php' ),
			),
			array(
				UserAgentSignatures::CATEGORY_SEARCH_ENGINE => $bundled->pathFor( 'signatures/ua-search-engine-providers.php' ),
				UserAgentSignatures::CATEGORY_SEO_CRAWLER => $bundled->pathFor( 'signatures/ua-seo-crawler-providers.php' ),
				UserAgentSignatures::CATEGORY_AI_CRAWLER  => $bundled->pathFor( 'signatures/ua-ai-crawler-providers.php' ),
			)
		);

		$datacenter = new DatacenterDetector(
			new IpRangeLookup( $bundled->providersIn( 'datacenter-ip-ranges' ) )
		);

		// Share one RealIpResolver between Classifier and Pipeline so
		// the resolved client IP is consistent across classification
		// and rate-limit counter keying.
		$real_ip_resolver = new RealIpResolver( $cdn );

		global $wpdb;
		$db_storage   = isset( $wpdb ) ? DbStorageFactory::detect( $wpdb ) : DbStorageFactory::nullPair();
		$rate_limiter = new RateLimiter(
			$db_storage['counter'],
			$db_storage['block'],
			$preset,
			null,
			self::resolveWindowSeconds()
		);

		$rdns_overrides = self::rdnsResolverOverrides();
		$rdns_reverse   = isset( $rdns_overrides['reverse'] ) ? $rdns_overrides['reverse'] : null;
		$rdns_forward   = isset( $rdns_overrides['forward'] ) ? $rdns_overrides['forward'] : null;

		$make_rdns_verifier = function ( $suffix_file, $key_prefix ) use ( $db_storage, $bundled, $rdns_reverse, $rdns_forward ) {
			return new RdnsVerifier(
				$db_storage['counter'],
				RdnsVerifier::loadProvidersFromFile( $bundled->pathFor( $suffix_file ) ),
				$rdns_reverse,
				$rdns_forward,
				$key_prefix
			);
		};

		$rdns_verifier     = $make_rdns_verifier( 'signatures/ua-rdns-suffixes.php', 'rdns:se:' );
		$ai_rdns_verifier  = $make_rdns_verifier( 'signatures/ua-ai-rdns-suffixes.php', 'rdns:ai:' );
		$seo_rdns_verifier = $make_rdns_verifier( 'signatures/ua-seo-rdns-suffixes.php', 'rdns:seo:' );

		$classifier = new Classifier(
			$signatures,
			$real_ip_resolver,
			new IpRangeLookup( $search_engines ),
			new IpRangeLookup( $ai_crawlers ),
			new IpRangeLookup( $seo_crawlers ),
			$datacenter,
			$rdns_verifier,
			$ai_rdns_verifier,
			$seo_rdns_verifier,
			new IpRangeLookup( $partition['ai_token_scoped'] )
		);

		// Share the storage between rate limiter and daily counter so
		// the widget reads the same keyspace the pipeline writes.
		$daily_counter = new DailyCounter( $db_storage['counter'] );

		// Durable hourly rollup + per-IP detail for the dashboard. Attached
		// only when the site owner has stats capture on and a DB handle is
		// available; otherwise the pipeline records no detailed stats (fail-open).
		$stats_storage    = $stats_enabled ? HourlyStatsStorage::forGlobalWpdb() : null;
		$ip_stats_storage = $stats_enabled ? HourlyIpStatsStorage::forGlobalWpdb() : null;

		// One file read, no database query: the IP step and SiteOwnerMatcher
		// share it.
		if ( null === $site_allowlist ) {
			$site_allowlist = SiteAllowlistFile::forContentDir( $wp_content_dir )->read();
		}
		$routes = new RestRouteResolver( $pretty_permalinks, $form_post, $home_path );

		// Built-in rules before the site owner's, so a request both cover is
		// recorded under the built-in type. Same-server last: the matchers
		// above are cheaper and already cover most internal traffic.
		$allowlist = new RequestAllowlist(
			array(
				new WordPressInternalsMatcher( self::isDoingCron(), $home_path, $site_path, $routes ),
				new WooCommerceMatcher( $home_path, $form_post, $pretty_permalinks ),
				new RestNamespaceMatcher(
					BundledData::loadArrayFile( $bundled->pathFor( 'signatures/rest-namespaces.php' ), 'signatures' ),
					$pretty_permalinks,
					$form_post,
					$home_path
				),
				new MonitoringUaMatcher(),
				new SiteOwnerMatcher(
					$site_allowlist,
					$routes,
					$form_post,
					$home_path,
					$site_path
				),
				new SameServerMatcher( new SelfOriginDetector( $server_addr, $cdn ) ),
			)
		);

		return new Pipeline(
			$classifier,
			$rate_limiter,
			$allowlist,
			$responder,
			$real_ip_resolver,
			$daily_counter,
			$stats_storage,
			$ip_stats_storage,
			IpWhitelist::forContentDir( $wp_content_dir ),
			$site_allowlist
		);
	}

	/**
	 * Resolve the main plugin directory whether WP_PLUGIN_DIR is defined yet or not.
	 *
	 * @return string
	 */
	private static function pluginDir() {
		if ( defined( 'IMUNIFY_SECURITY_PATH' ) ) {
			return (string) IMUNIFY_SECURITY_PATH;
		}
		if ( defined( 'WP_PLUGIN_DIR' ) ) {
			return (string) WP_PLUGIN_DIR . '/imunify-security';
		}
		// Dev / test fallback — derive from this file's location.
		// __DIR__ = .../inc/App/Bot → go up three levels to plugin root.
		// Using nested dirname() to stay PHP 5.6 compatible (the 2-arg
		// form was added in PHP 7.0).
		return dirname( dirname( dirname( __DIR__ ) ) );
	}

	/**
	 * Absolute path to the overlay directory that SignatureRefresher writes to.
	 *
	 * @param string $wp_content_dir Absolute path to wp-content.
	 * @return string
	 */
	private static function overlayDir( $wp_content_dir ) {
		return rtrim( $wp_content_dir, '/' ) . '/imunify-security/bot-data';
	}
}

Directory Contents

Dirs: 1 × Files: 77
Name Size Perms Modified Actions
data DIR
- drwxr-xr-x 2026-11-03 01:06:25
Edit Download
11.48 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.43 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.47 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.38 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
4.45 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.17 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.01 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
21.21 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.34 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
17.81 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
3.38 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.79 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
13.17 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
8.77 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.67 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
14.53 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
4.25 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.72 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.58 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.55 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
14.00 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.58 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.99 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.88 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.41 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.53 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.61 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
4.73 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.49 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
17.86 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
14.97 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.47 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
4.76 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.06 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.26 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.64 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.68 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
10.47 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.49 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
17.09 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
8.51 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
12.60 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
3.46 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
835 B lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.71 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
22.44 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.65 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.33 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
892 B lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
924 B lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
4.69 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
18.57 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
6.92 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
3.87 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.94 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
18.17 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
8.48 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.80 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
9.49 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.84 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.45 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.28 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.27 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
9.90 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
15.82 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
20.41 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
7.79 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.61 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.80 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
30.46 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
2.79 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
1.41 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
3.72 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
9.60 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.05 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
6.56 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
5.16 KB lrwxr-xr-x 2026-11-03 01:06:25
Edit Download
If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 0xNothings — Secure File Manager. All rights reserved. Built with ❤️ & Tailwind x Dark UI