about summary refs log tree commit diff
path: root/app/validators
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-12-10 06:27:26 +0100
committerGitHub <noreply@github.com>2020-12-10 06:27:26 +0100
commit49eb4d4ddf61e25c5aaab89aa630ddd3c7f3c23d (patch)
tree3ed700750271b0ac8892f2282325d9838b915446 /app/validators
parent9669167aaeaa834dcc99fa7df961c4f9b8118850 (diff)
Add honeypot fields and minimum fill-out time for sign-up form (#15276)
* Add honeypot fields to limit non-specialized spam

Add two honeypot fields: a fake website input and a fake password confirmation
one. The label/placeholder/aria-label tells not to fill them, and they are
hidden in CSS, so legitimate users should not fall into these.

This should cut down on some non-Mastodon-specific spambots.

* Require a 3 seconds delay before submitting the registration form

* Fix tests

* Move registration form time check to model validation

* Give people a chance to clear the honeypot fields

* Refactor honeypot translation strings

Co-authored-by: Claire <claire.github-309c@sitedethib.com>
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/registration_form_time_validator.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/validators/registration_form_time_validator.rb b/app/validators/registration_form_time_validator.rb
new file mode 100644
index 000000000..ba7c7e6c6
--- /dev/null
+++ b/app/validators/registration_form_time_validator.rb
@@ -0,0 +1,9 @@
+# frozen_string_literal: true
+
+class RegistrationFormTimeValidator < ActiveModel::Validator
+  REGISTRATION_FORM_MIN_TIME = 3.seconds.freeze
+
+  def validate(user)
+    user.errors.add(:base, I18n.t('auth.too_fast')) if user.registration_form_time.present? && user.registration_form_time > REGISTRATION_FORM_MIN_TIME.ago
+  end
+end