From 220b9c5abe561a8bed3192b54472f7c347bdda55 Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Wed, 13 May 2015 17:38:10 +0530 Subject: [PATCH] FIX: match subdomain with email domain blacklist --- lib/validators/email_validator.rb | 2 +- spec/models/user_spec.rb | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/validators/email_validator.rb b/lib/validators/email_validator.rb index e0e759571..c9f588976 100644 --- a/lib/validators/email_validator.rb +++ b/lib/validators/email_validator.rb @@ -17,7 +17,7 @@ class EmailValidator < ActiveModel::EachValidator def email_in_restriction_setting?(setting, value) domains = setting.gsub('.', '\.') - regexp = Regexp.new("@(#{domains})", true) + regexp = Regexp.new("@(.+\.)?(#{domains})", true) value =~ regexp end diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 58a48f71d..799b1e9b9 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -440,6 +440,11 @@ describe User do expect(Fabricate.build(:user, email: 'notgood@TRASHMAIL.NET')).not_to be_valid end + it 'should reject emails based on the email_domains_blacklist site setting matching subdomain' do + SiteSetting.stubs(:email_domains_blacklist).returns('domain.com') + expect(Fabricate.build(:user, email: 'notgood@sub.domain.com')).not_to be_valid + end + it 'blacklist should not reject developer emails' do Rails.configuration.stubs(:developer_emails).returns('developer@discourse.org') SiteSetting.stubs(:email_domains_blacklist).returns('discourse.org')