Avoid problems with an empty domain in the blocklist (#13919)
authorMichael Vogel <icarus@dabo.de>
Mon, 19 Feb 2024 06:22:19 +0000 (07:22 +0100)
committerGitHub <noreply@github.com>
Mon, 19 Feb 2024 06:22:19 +0000 (07:22 +0100)
* Avoid problems with an empty domain in the blocklist

* Test code removed

src/Module/Moderation/Blocklist/Server/Index.php
src/Util/Network.php

index 740d7b0..3b6dc73 100644 (file)
@@ -57,11 +57,11 @@ class Index extends BaseModeration
 
                // Edit the entries from blocklist
                $blocklist = [];
-               foreach ($request['domain'] as $id => $domain) {
+               foreach ((array)$request['domain'] as $id => $domain) {
                        // Trimming whitespaces as well as any lingering slashes
                        $domain = trim($domain);
                        $reason = trim($request['reason'][$id]);
-                       if (empty($request['delete'][$id])) {
+                       if (empty($request['delete'][$id]) && !empty($domain)) {
                                $blocklist[] = [
                                        'domain' => $domain,
                                        'reason' => $reason
index 02124a4..12dde0a 100644 (file)
@@ -217,7 +217,7 @@ class Network
                }
 
                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;
                        }
                }