]> git.mxchange.org Git - friendica.git/commitdiff
Compare lengths of hashtags with the content length for improved spam detection
authorMichael <heluecht@pirati.ca>
Fri, 26 Jan 2024 11:22:01 +0000 (11:22 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 26 Jan 2024 11:22:01 +0000 (11:22 +0000)
src/Protocol/Relay.php
static/settings.config.php

index 9c16e5e1eefc67ea19aea9a7dac754bb18627e13..b972871aa3215013b0435e34560dbe4d8b4e09c5 100644 (file)
@@ -113,13 +113,18 @@ class Relay
                }
 
                if (!empty($tagList) || !empty($denyTags)) {
+                       $content = mb_strtolower(BBCode::toPlaintext($body, false));
+
                        $max_tags = $config->get('system', 'relay_max_tags');
                        if ($max_tags && (count($tags) > $max_tags) && preg_match('/[^@!#]\[url\=.*?\].*?\[\/url\]/ism', $body)) {
-                               Logger::info('Possible hashtag spam detected - rejected', ['hashtags' => $tags, 'network' => $network, 'url' => $url, 'causer' => $causer, 'body' => $body]);
-                               return false;
-                       }
+                               $cleaned = preg_replace('/[@!#]\[url\=.*?\].*?\[\/url\]/ism', '', $body);
+                               $content_cleaned = mb_strtolower(BBCode::toPlaintext($cleaned, false));
 
-                       $content = mb_strtolower(BBCode::toPlaintext($body, false));
+                               if (strlen($content_cleaned) < (strlen($content) - strlen($content_cleaned))) {
+                                       Logger::info('Possible hashtag spam detected - rejected', ['hashtags' => $tags, 'network' => $network, 'url' => $url, 'causer' => $causer, 'body' => $body]);
+                                       return false;
+                               }
+                       }
 
                        foreach ($tags as $tag) {
                                $tag = mb_strtolower($tag);
index 0e8d73015793b322bc68b0600a3c2ebd3ed92eac..5bd1f2f193aaf51d24c546f30446ef3b587c8e50 100644 (file)
@@ -239,7 +239,7 @@ return [
 
                // relay_max_tags (Integer)
                // Maximum amount of tags in a post before it is rejected as spam.
-               'relay_max_tags' => 10,
+               'relay_max_tags' => 20,
 
                // proxify_content (Boolean)
                // Use the proxy functionality for fetching external content