Avoid problems with an empty domain in the blocklist

This commit is contained in:
Michael 2024-02-19 02:26:21 +00:00
parent 7d5d3b3c29
commit a299353dce
2 changed files with 4 additions and 3 deletions

View file

@ -57,11 +57,11 @@ class Index extends BaseModeration
// Edit the entries from blocklist // Edit the entries from blocklist
$blocklist = []; $blocklist = [];
foreach ($request['domain'] as $id => $domain) { foreach ((array)$request['domain'] as $id => $domain) {
// Trimming whitespaces as well as any lingering slashes // Trimming whitespaces as well as any lingering slashes
$domain = trim($domain); $domain = trim($domain);
$reason = trim($request['reason'][$id]); $reason = trim($request['reason'][$id]);
if (empty($request['delete'][$id])) { if (empty($request['delete'][$id]) && !empty($domain)) {
$blocklist[] = [ $blocklist[] = [
'domain' => $domain, 'domain' => $domain,
'reason' => $reason 'reason' => $reason
@ -69,6 +69,7 @@ class Index extends BaseModeration
} }
} }
$this->logger->debug('Blubb', ['blocklist' => $blocklist]);
$this->blocklist->set($blocklist); $this->blocklist->set($blocklist);
Worker::add(Worker::PRIORITY_LOW, 'UpdateBlockedServers'); Worker::add(Worker::PRIORITY_LOW, 'UpdateBlockedServers');

View file

@ -217,7 +217,7 @@ class Network
} }
foreach ($domain_blocklist as $domain_block) { foreach ($domain_blocklist as $domain_block) {
if (fnmatch(strtolower($domain_block['domain']), strtolower($uri->getHost()))) { if (!empty($domain_block['domain']) && fnmatch(strtolower($domain_block['domain']), strtolower($uri->getHost()))) {
return true; return true;
} }
} }