Skip to content

Commit 9a8cc03

Browse files
authored
Fix. FW. Improve AC module to correct processing loopback. (#862)
* Fix. FW. Improve AC module to correct processing loopback. * fix cp * fix psalm
1 parent 3a82ac5 commit 9a8cc03

15 files changed

Lines changed: 130 additions & 15 deletions

cleantalk.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ function apbct_register_my_rest_routes()
347347
&& empty(Post::get('action')) //bbPress
348348
&& ! \Cleantalk\Variables\Server::inUri('/favicon.ico') // /favicon request rewritten cookies fix
349349
&& ! apbct__is_wp_rocket_preloader_request()
350+
&& ! apbct__is_wordpress_loopback_request()
350351
) {
351352
if ( $apbct->data['cookies_type'] !== 'alternative' ) {
352353
if ( !$apbct->settings['forms__search_test'] && !Get::get('s') ) { //skip cookie set for search form redirect page

inc/cleantalk-ajax.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,6 @@ function ct_ajax_hook($message_obj = null)
894894
'message' => $ct_result->comment
895895
)
896896
);
897-
die();
898897
}
899898

900899
// Plugin Name: eForm - WordPress Form Builder; ajax action ipt_fsqm_save_form

inc/cleantalk-pluggable.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,6 +2235,58 @@ function apbct__is_wp_rocket_preloader_request()
22352235
);
22362236
}
22372237

2238+
/**
2239+
* True for WordPress HTTP API loopback requests (Site Health, updates, cron).
2240+
* Default WP user-agent: "WordPress/{version}; {siteurl}"
2241+
*
2242+
* Requires both the WordPress UA prefix and that the URL in the UA belongs
2243+
* to this site. UA-only matching would skip Anti-Crawler for any spoofed
2244+
* WordPress client, including requests from other sites.
2245+
*
2246+
* Do not require REMOTE_ADDR === SERVER_ADDR: php-fpm loopbacks often arrive
2247+
* from the public origin IP while SERVER_ADDR is 127.0.0.1.
2248+
*
2249+
* @return bool
2250+
*/
2251+
function apbct__is_wordpress_loopback_request()
2252+
{
2253+
if ( ! isset($_SERVER['HTTP_USER_AGENT']) ) {
2254+
return false;
2255+
}
2256+
2257+
if ( preg_match('#^WordPress/\d[\d.]*;\s+(\S+)#', $_SERVER['HTTP_USER_AGENT'], $matches) !== 1 ) {
2258+
return false;
2259+
}
2260+
2261+
$ua_url = isset($matches[1]) ? $matches[1] : '';
2262+
if ( $ua_url === '' ) {
2263+
return false;
2264+
}
2265+
2266+
$ua_host = wp_parse_url($ua_url, PHP_URL_HOST);
2267+
if ( ! is_string($ua_host) || $ua_host === '' ) {
2268+
return false;
2269+
}
2270+
$ua_host = strtolower($ua_host);
2271+
2272+
$site_hosts = array();
2273+
foreach ( array(home_url(), site_url()) as $url ) {
2274+
$host = wp_parse_url($url, PHP_URL_HOST);
2275+
if ( is_string($host) && $host !== '' ) {
2276+
$site_hosts[] = strtolower($host);
2277+
}
2278+
}
2279+
2280+
if ( isset($_SERVER['HTTP_HOST']) ) {
2281+
$host_header = preg_replace('/:\d+$/', '', $_SERVER['HTTP_HOST']);
2282+
if ( is_string($host_header) && $host_header !== '' ) {
2283+
$site_hosts[] = strtolower($host_header);
2284+
}
2285+
}
2286+
2287+
return in_array($ua_host, $site_hosts, true);
2288+
}
2289+
22382290
/**
22392291
* Generates MD5 hash for email encoder pass key
22402292
*

inc/cleantalk-public-integrations.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,9 +2448,6 @@ function apbct_form__the7_contact_form()
24482448
);
24492449

24502450
wp_send_json($response);
2451-
2452-
// IMPORTANT: don't forget to "exit" @todo AG: Why? Exit does not terminate connection, but I can't see how it is applicable
2453-
exit;
24542451
}
24552452
}
24562453
}

lib/Cleantalk/Antispam/Integrations/ChatyContactForm.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,5 @@ public function doBlock($message)
4141
'message' => $message,
4242
];
4343
wp_send_json($response);
44-
exit;
4544
}
4645
}

lib/Cleantalk/Antispam/Integrations/ElementorUltimateAddonsRegister.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public function doBlock($message)
2424
)
2525
)
2626
);
27-
return false;
2827
}
2928

3029
public function allow()

lib/Cleantalk/Antispam/Integrations/HivePress.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,5 @@ public function doBlock($message)
3939
'error' => ['message' => $message],
4040
]
4141
);
42-
die();
4342
}
4443
}

lib/Cleantalk/Antispam/Integrations/HivePressRegistration.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@ public function doBlock($message)
3535
'error' => ['message' => $message],
3636
]
3737
);
38-
die();
3938
}
4039
}

lib/Cleantalk/Antispam/Integrations/MailPoet.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,5 @@ public function doBlock($message)
5858
),
5959
403
6060
);
61-
die();
6261
}
6362
}

lib/Cleantalk/Antispam/Integrations/SureForms.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,5 @@ public function doBlock($message)
2929
'message' => $message
3030
)
3131
);
32-
die();
3332
}
3433
}

0 commit comments

Comments
 (0)