about summary refs log tree commit diff
path: root/app/workers
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-09-06 01:57:13 -0500
committermultiple creatures <dev@multiple-creature.party>2019-09-06 01:57:13 -0500
commitbb5119adb615c5a4c88de6dfb85c49d8f1f90002 (patch)
treee48db9b6906313259d8461163f71991947143e81 /app/workers
parent41b86307a36c62c037d920b46ee87c3eb3526c50 (diff)
convert spam filters into unioned regex, match between word boundaries
Diffstat (limited to 'app/workers')
-rw-r--r--app/workers/registration_janitor_worker.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/app/workers/registration_janitor_worker.rb b/app/workers/registration_janitor_worker.rb
index e3130a6bb..c3250f993 100644
--- a/app/workers/registration_janitor_worker.rb
+++ b/app/workers/registration_janitor_worker.rb
@@ -8,13 +8,14 @@ class RegistrationJanitorWorker
     user = User.find(user_id)
     janitor = janitor_account || Account.representative
 
-    spam_triggers = ENV.fetch('REGISTRATION_SPAM_TRIGGERS', '').split('|').map { |phrase| phrase.strip }
+    spam_triggers = ENV.fetch('REGISTRATION_SPAM_TRIGGERS', '').split('|').map { |phrase| Regexp.escape(phrase.strip) }
+    spam_triggers = spam_triggers.empty? ? /(?!)/ : /\b#{Regexp.union(spam_triggers)}\b/i
 
     intro = user.invite_request&.text
     # normalize it
     intro = intro.gsub(/[\u200b-\u200d\ufeff\u200e\u200f]/, '').strip.downcase unless intro.nil?
 
-    return user.notify_staff_about_pending_account! unless intro.blank? || intro.split.count < 5 || spam_triggers.any? { |phrase| phrase.in?(intro) }
+    return user.notify_staff_about_pending_account! unless intro.blank? || intro.split.count < 5 || spam_triggers.match?(intro)
 
     user_friendly_action_log(janitor, :reject_registration, user.account.username, "Registration was spam filtered.")
     Form::AccountBatch.new(current_account: janitor, account_ids: user.account.id, action: 'reject').save