add banned email blacklist

This commit is contained in:
Kyle Drake 2018-06-10 17:54:35 -07:00
parent 951e66861e
commit a8d64e0af5

View file

@ -128,6 +128,7 @@ class Site < Sequel::Model
EMAIL_VALIDATION_CUTOFF_DATE = Time.parse('May 16, 2016') EMAIL_VALIDATION_CUTOFF_DATE = Time.parse('May 16, 2016')
DISPOSABLE_EMAIL_BLACKLIST_PATH = File.join(DIR_ROOT, 'files', 'disposable_email_blacklist.conf') DISPOSABLE_EMAIL_BLACKLIST_PATH = File.join(DIR_ROOT, 'files', 'disposable_email_blacklist.conf')
BANNED_EMAIL_BLACKLIST_PATH = File.join(DIR_ROOT, 'files', 'banned_email_blacklist.conf')
BLOCK_JERK_THRESHOLD = 2 BLOCK_JERK_THRESHOLD = 2
MAXIMUM_TAGS = 5 MAXIMUM_TAGS = 5
@ -587,6 +588,10 @@ class Site < Sequel::Model
File.readlines(DISPOSABLE_EMAIL_BLACKLIST_PATH).collect {|d| d.strip} File.readlines(DISPOSABLE_EMAIL_BLACKLIST_PATH).collect {|d| d.strip}
end end
def self.banned_email_domains
File.readlines(BANNED_EMAIL_BLACKLIST_PATH).collect {|d| d.strip}
end
def self.disposable_mx_record?(email) def self.disposable_mx_record?(email)
email_domain = email.match(/@(.+)/).captures.first email_domain = email.match(/@(.+)/).captures.first
@ -615,6 +620,19 @@ class Site < Sequel::Model
false false
end end
def self.banned_email?(email)
return false unless File.exist?(BANNED_EMAIL_BLACKLIST_PATH)
return false if email.blank?
email.strip!
banned_email_domains.each do |banned_email_domain|
return true if email.match /@#{banned_email_domain}$/i
end
false
end
def okay_to_upload?(uploaded_file) def okay_to_upload?(uploaded_file)
return true if [:supporter].include?(plan_type.to_sym) return true if [:supporter].include?(plan_type.to_sym)
return false if self.class.possible_phishing?(uploaded_file) return false if self.class.possible_phishing?(uploaded_file)
@ -993,6 +1011,10 @@ class Site < Sequel::Model
errors.add :email, 'Cannot use a disposable email address.' errors.add :email, 'Cannot use a disposable email address.'
end end
if parent? && (values[:created_at].nil? || values[:created_at] > 1.week.ago) && self.class.banned_email?(values[:email])
errors.add :email, 'Registration from this domain is banned due to abuse.'
end
# Check for existing email if new or changing email. # Check for existing email if new or changing email.
if new? || @original_email if new? || @original_email
email_check = self.class.select(:id).filter('lower(email)=?', values[:email]) email_check = self.class.select(:id).filter('lower(email)=?', values[:email])