Anti spam measures against hashtag spam (#13855)

This commit is contained in:
Michael Vogel 2024-01-25 19:41:07 +01:00 committed by GitHub
parent b3e4b9675a
commit 09edf251ee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 278 additions and 252 deletions

View file

@ -159,6 +159,7 @@ class Site extends BaseAdmin
$relay_scope = (!empty($_POST['relay_scope']) ? trim($_POST['relay_scope']) : '');
$relay_server_tags = (!empty($_POST['relay_server_tags']) ? trim($_POST['relay_server_tags']) : '');
$relay_deny_tags = (!empty($_POST['relay_deny_tags']) ? trim($_POST['relay_deny_tags']) : '');
$relay_max_tags = (!empty($_POST['relay_max_tags']) ? intval($_POST['relay_max_tags']) : 0);
$relay_user_tags = !empty($_POST['relay_user_tags']);
$relay_deny_undetected_language = !empty($_POST['relay_deny_undetected_language']);
@ -333,6 +334,7 @@ class Site extends BaseAdmin
$transactionConfig->set('system', 'relay_scope' , $relay_scope);
$transactionConfig->set('system', 'relay_server_tags' , $relay_server_tags);
$transactionConfig->set('system', 'relay_deny_tags' , $relay_deny_tags);
$transactionConfig->set('system', 'relay_max_tags' , $relay_max_tags);
$transactionConfig->set('system', 'relay_user_tags' , $relay_user_tags);
$transactionConfig->set('system', 'relay_deny_undetected_language', $relay_deny_undetected_language);
$transactionConfig->set('system', 'relay_language_quality' , $relay_language_quality);
@ -586,6 +588,7 @@ class Site extends BaseAdmin
'$relay_scope' => ['relay_scope', DI::l10n()->t('Relay scope'), DI::config()->get('system', 'relay_scope'), DI::l10n()->t('Can be "all" or "tags". "all" means that every public post should be received. "tags" means that only posts with selected tags should be received.'), [Relay::SCOPE_NONE => DI::l10n()->t('Disabled'), Relay::SCOPE_ALL => DI::l10n()->t('all'), Relay::SCOPE_TAGS => DI::l10n()->t('tags')]],
'$relay_server_tags' => ['relay_server_tags', DI::l10n()->t('Server tags'), DI::config()->get('system', 'relay_server_tags'), DI::l10n()->t('Comma separated list of tags for the "tags" subscription.')],
'$relay_deny_tags' => ['relay_deny_tags', DI::l10n()->t('Deny Server tags'), DI::config()->get('system', 'relay_deny_tags'), DI::l10n()->t('Comma separated list of tags that are rejected.')],
'$relay_max_tags' => ['relay_max_tags', DI::l10n()->t('Maximum amount of tags'), DI::config()->get('system', 'relay_max_tags'), DI::l10n()->t('Maximum amount of tags in a post before it is rejected as spam. The post has to contain at least one link. Posts from subscribed accounts will not be rejected.')],
'$relay_user_tags' => ['relay_user_tags', DI::l10n()->t('Allow user tags'), DI::config()->get('system', 'relay_user_tags'), DI::l10n()->t('If enabled, the tags from the saved searches will used for the "tags" subscription in addition to the "relay_server_tags".')],
'$relay_deny_undetected_language' => ['relay_deny_undetected_language', DI::l10n()->t('Deny undetected languages'), DI::config()->get('system', 'relay_deny_undetected_language'), DI::l10n()->t('If enabled, posts with undetected languages will be rejected.')],
'$relay_language_quality' => ['relay_language_quality', DI::l10n()->t('Language Quality'), DI::config()->get('system', 'relay_language_quality'), DI::l10n()->t('The minimum language quality that is required to accept the post.')],

View file

@ -113,6 +113,12 @@ class Relay
}
if (!empty($tagList) || !empty($denyTags)) {
$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;
}
$content = mb_strtolower(BBCode::toPlaintext($body, false));
foreach ($tags as $tag) {

View file

@ -237,6 +237,10 @@ return [
// Minimum value for the language detection quality for relay posts. The value must be between 0 and 1.
'relay_language_quality' => 0,
// relay_max_tags (Integer)
// Maximum amount of tags in a post before it is rejected as spam.
'relay_max_tags' => 10,
// proxify_content (Boolean)
// Use the proxy functionality for fetching external content
'proxify_content' => true,

File diff suppressed because it is too large Load diff

View file

@ -160,6 +160,7 @@
{{include file="field_select.tpl" field=$relay_scope}}
{{include file="field_input.tpl" field=$relay_server_tags}}
{{include file="field_input.tpl" field=$relay_deny_tags}}
{{include file="field_input.tpl" field=$relay_max_tags}}
{{include file="field_checkbox.tpl" field=$relay_user_tags}}
{{include file="field_checkbox.tpl" field=$relay_directly}}
{{include file="field_checkbox.tpl" field=$relay_deny_undetected_language}}

View file

@ -329,6 +329,7 @@
{{include file="field_select.tpl" field=$relay_scope}}
{{include file="field_input.tpl" field=$relay_server_tags}}
{{include file="field_input.tpl" field=$relay_deny_tags}}
{{include file="field_input.tpl" field=$relay_max_tags}}
{{include file="field_checkbox.tpl" field=$relay_user_tags}}
{{include file="field_checkbox.tpl" field=$relay_directly}}
{{include file="field_checkbox.tpl" field=$relay_deny_undetected_language}}