Add possible regex handling

This commit is contained in:
Maingron
2025-09-13 02:11:39 +02:00
parent 5247655a50
commit bd050d27c4

View File

@@ -45,10 +45,17 @@ function better_blacklist_domain_check( $shunt, $url ) {
$blacklisted_domains = unserialize( $blacklisted_domains );
foreach ( $blacklisted_domains as $blacklisted_domain ) {
// Use a regex to match the domain or subdomain
$pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i';
if ( preg_match( $pattern, $domain ) ) {
return blacklist_fail_response();
// Check if the entry starts with '/', then consider regex handling
if (strpos($blacklisted_domain, '/') === 0) {
if (@preg_match($blacklisted_domain, $domain)) {
return blacklist_fail_response();
}
} else {
// Otherwise treat as plain domain (old behavior)
$pattern = '/(?:^|\.)' . preg_quote( $blacklisted_domain, '/' ) . '$/i';
if ( preg_match( $pattern, $domain ) ) {
return blacklist_fail_response();
}
}
}
}