Apologies for the delay. I’ve just had time to look at the code, so here’s why your script is being blocked by browsers:
if ($attempts > 10) {
add_action("wp_head", "wordfence::addSyncAttackDataAjax");
add_action("login_head", "wordfence::addSyncAttackDataAjax");
add_action("admin_head", "wordfence::addSyncAttackDataAjax");
} else {
update_site_option("wordfence_syncAttackDataAttempts", ++$attempts);
wp_remote_post(
add_query_arg(
"wordfence_syncAttackData",
microtime(true),
home_url("/")
),
[
"timeout" => 0.01,
"blocking" => false,
"sslverify" => apply_filters("https_local_ssl_verify", false),
]
);
}
The second method is OK because wp_remote_post
is a loopback request that bypasses the browser. The trouble is with the first method, which gets triggered like you say when there’s a bout of attacks. Let’s see what it’s doing:
public static function addSyncAttackDataAjax() {
$URL = home_url('/?wordfence_syncAttackData=' . microtime(true));
$URL = esc_url(preg_replace('/^https?:/i', '', $URL));
// Load as external script async so we don't slow page down.
echo "<script type=\"text/javascript\" src=\"$URL\" async></script>";
}
So that’s why it’s getting blocked! The type
attribute won’t work as intended when a site is using a caching solution that’s set to ignore query strings, a common technique to obviate query string-based DDoS attacks. That’s because a request like this would simply return the cache of home URL with a MIME type of text/html
, triggering a nosniff block by browsers:
Refused to execute https://www.example.com/?wordfence_syncAttackData=1728611106.9776 as script because "X-Content-Type-Options: nosniff" was given and its Content-Type is not a script MIME type.
What we would like to see is a toggle that lets webmasters to opt out of this ‘script’ method on sites that have this rather common setup.