email_check 0.1.4 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/codeql-analysis.yml +70 -0
- data/.travis.yml +12 -3
- data/README.md +36 -20
- data/SECURITY.md +14 -0
- data/email_check.gemspec +2 -2
- data/gemfiles/activemodel5.gemfile +5 -0
- data/gemfiles/activemodel6.gemfile +5 -0
- data/lib/email_check/email_address.rb +7 -6
- data/lib/email_check/email_validator.rb +29 -15
- data/lib/email_check/helper_methods.rb +27 -0
- data/lib/email_check/version.rb +1 -1
- data/lib/email_check.rb +1 -0
- data/vendor/blacklist.yml +1 -0
- data/vendor/free.yml +512 -1
- metadata +15 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: be0cba5ca74845cdd02da6697b576bd3a38947116123179123dae393fd0247e3
|
4
|
+
data.tar.gz: 865c687b2a7c627da107d4157057d9a3dbb6d9de0203b94c90b0ccd40abf6578
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c1afee8e164514a3f5f74dddf556b494be9a4fffc459322765a808bd4a944b4e8452b308016d864299d50bb15dc40a10ec513d38c12971577d246fec69e2aaa0
|
7
|
+
data.tar.gz: 90c4f836d99891b514b9aee8da286af6ffa3910bc10d5312df949dde633cb7c13c76733cf023b70224f608abfc195934bdf8f216cf6ab989976769b6d3a2eb3c
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# For most projects, this workflow file will not need changing; you simply need
|
2
|
+
# to commit it to your repository.
|
3
|
+
#
|
4
|
+
# You may wish to alter this file to override the set of languages analyzed,
|
5
|
+
# or to provide custom queries or build logic.
|
6
|
+
#
|
7
|
+
# ******** NOTE ********
|
8
|
+
# We have attempted to detect the languages in your repository. Please check
|
9
|
+
# the `language` matrix defined below to confirm you have the correct set of
|
10
|
+
# supported CodeQL languages.
|
11
|
+
#
|
12
|
+
name: "CodeQL"
|
13
|
+
|
14
|
+
on:
|
15
|
+
push:
|
16
|
+
branches: [ master ]
|
17
|
+
pull_request:
|
18
|
+
# The branches below must be a subset of the branches above
|
19
|
+
branches: [ master ]
|
20
|
+
schedule:
|
21
|
+
- cron: '16 2 * * 5'
|
22
|
+
|
23
|
+
jobs:
|
24
|
+
analyze:
|
25
|
+
name: Analyze
|
26
|
+
runs-on: ubuntu-latest
|
27
|
+
permissions:
|
28
|
+
actions: read
|
29
|
+
contents: read
|
30
|
+
security-events: write
|
31
|
+
|
32
|
+
strategy:
|
33
|
+
fail-fast: false
|
34
|
+
matrix:
|
35
|
+
language: [ 'ruby' ]
|
36
|
+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ]
|
37
|
+
# Learn more about CodeQL language support at https://git.io/codeql-language-support
|
38
|
+
|
39
|
+
steps:
|
40
|
+
- name: Checkout repository
|
41
|
+
uses: actions/checkout@v3
|
42
|
+
|
43
|
+
# Initializes the CodeQL tools for scanning.
|
44
|
+
- name: Initialize CodeQL
|
45
|
+
uses: github/codeql-action/init@v1
|
46
|
+
with:
|
47
|
+
languages: ${{ matrix.language }}
|
48
|
+
# If you wish to specify custom queries, you can do so here or in a config file.
|
49
|
+
# By default, queries listed here will override any specified in a config file.
|
50
|
+
# Prefix the list here with "+" to use these queries and those in the config file.
|
51
|
+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
52
|
+
|
53
|
+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
54
|
+
# If this step fails, then you should remove it and run the build manually (see below)
|
55
|
+
- name: Autobuild
|
56
|
+
uses: github/codeql-action/autobuild@v1
|
57
|
+
|
58
|
+
# ℹ️ Command-line programs to run using the OS shell.
|
59
|
+
# 📚 https://git.io/JvXDl
|
60
|
+
|
61
|
+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
62
|
+
# and modify them (or add more) to build your code if your project
|
63
|
+
# uses a compiled language
|
64
|
+
|
65
|
+
#- run: |
|
66
|
+
# make bootstrap
|
67
|
+
# make release
|
68
|
+
|
69
|
+
- name: Perform CodeQL Analysis
|
70
|
+
uses: github/codeql-action/analyze@v1
|
data/.travis.yml
CHANGED
@@ -1,9 +1,18 @@
|
|
1
1
|
language: ruby
|
2
2
|
rvm:
|
3
|
-
- 2.
|
4
|
-
- 2.
|
5
|
-
- 2.0.0
|
3
|
+
- 2.3.0
|
4
|
+
- 2.5.0
|
6
5
|
|
7
6
|
gemfile:
|
8
7
|
- gemfiles/activemodel4.gemfile
|
8
|
+
- gemfiles/activemodel5.gemfile
|
9
|
+
- gemfiles/activemodel6.gemfile
|
9
10
|
|
11
|
+
matrix:
|
12
|
+
exclude:
|
13
|
+
- rvm: 2.3.0
|
14
|
+
gemfile: gemfiles/activemodel6.gemfile
|
15
|
+
- rvm: 2.5.0
|
16
|
+
gemfile: gemfiles/activemodel4.gemfile
|
17
|
+
|
18
|
+
before_install: gem install bundler
|
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
[![Coverage Status][CS img]][Coverage Status]
|
8
8
|
|
9
9
|
## Description
|
10
|
-
This was built for [Anonybuzz](https://anonybuzz.com).
|
10
|
+
This was originally built for [Anonybuzz](https://anonybuzz.com) and is now used at [StarTalent](https://startalent.io).
|
11
11
|
This gem provides a robust mechanism to validate email addresses and restrict account creation to corporate email accounts.
|
12
12
|
|
13
13
|
This gem also ships with a data-set of free and [disposable](http://en.wikipedia.org/wiki/Disposable_email_address)
|
@@ -26,46 +26,57 @@ You can also block certain usernames from creating accounts. Examples: admin, ro
|
|
26
26
|
## Installation
|
27
27
|
Add this line to your application's Gemfile:
|
28
28
|
```ruby
|
29
|
-
gem "
|
29
|
+
gem "email_check"
|
30
30
|
```
|
31
31
|
|
32
32
|
## Usage
|
33
33
|
### Use with ActiveModel
|
34
|
-
To validate just the email address
|
34
|
+
To validate just the format of the email address
|
35
35
|
```ruby
|
36
36
|
class User < ActiveRecord::Base
|
37
|
-
|
37
|
+
validates_email :email
|
38
38
|
end
|
39
39
|
```
|
40
40
|
To validate that the domain has a MX record:
|
41
41
|
```ruby
|
42
|
-
|
42
|
+
validates_email :email, check_mx: true
|
43
43
|
```
|
44
44
|
To validate that the email is not from a disposable or free email provider:
|
45
45
|
```ruby
|
46
|
-
|
46
|
+
validates_email :email, not_disposable:true, not_free:true
|
47
47
|
```
|
48
48
|
To validate that the domain is not blacklisted:
|
49
49
|
```ruby
|
50
|
-
|
50
|
+
validates_email :email, not_blacklisted:true
|
51
51
|
```
|
52
52
|
|
53
53
|
To validate that the username is not blocked
|
54
54
|
```ruby
|
55
|
-
|
55
|
+
validates_email :email, block_special_usernames:true
|
56
|
+
```
|
56
57
|
|
57
58
|
Everything together:
|
58
59
|
```ruby
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
message: "Please register with your corporate email"
|
60
|
+
validates_email :email,
|
61
|
+
check_mx: true,
|
62
|
+
not_disposable:true,
|
63
|
+
not_free:true,
|
64
|
+
not_blacklisted:true,
|
65
|
+
block_special_usernames:true,
|
66
|
+
message: "Please register with your corporate email"
|
67
|
+
```
|
68
|
+
|
69
|
+
To turn everything on by default, you can use the validates_email_strictness helper.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# Example above
|
73
|
+
validates_email_strictness :email
|
74
|
+
|
75
|
+
# Everything but allow free emails. This is what most people would want to use
|
76
|
+
validates_email_strictness :email, not_free:false
|
66
77
|
```
|
67
78
|
|
68
|
-
### Modifying inbuilt lists
|
79
|
+
### Modifying the inbuilt lists
|
69
80
|
The lists are exposed as assignable arrays so you can customize them or load whatever data you please.
|
70
81
|
|
71
82
|
Add a config/intializers/email_check.rb
|
@@ -75,16 +86,21 @@ EmailCheck.disposable_email_domains = ['freemail.org']
|
|
75
86
|
# Append to the whitelist
|
76
87
|
EmailCheck.whitelisted_domains << 'gmail.com'
|
77
88
|
EmailCheck.free_email_domains << 'thenewgmail.com'
|
78
|
-
# Setting a domain in the blacklist also
|
89
|
+
# Setting a domain in the blacklist will also blacklist all subdomains
|
79
90
|
EmailCheck.blacklisted_domains << 'lvh.me'
|
91
|
+
# Block the 'anonymous' username for all domains
|
80
92
|
EmailCheck.blocked_usernames << 'anonymous'
|
81
93
|
```
|
82
94
|
|
83
95
|
## Requirements
|
84
96
|
This gem is tested with Rails 4.0+. Ruby versions tested:
|
85
|
-
- Ruby 2.
|
86
|
-
- Ruby 2.
|
87
|
-
|
97
|
+
- Ruby 2.3
|
98
|
+
- Ruby 2.5
|
99
|
+
|
100
|
+
Rails versions tested:
|
101
|
+
Rails 4.0
|
102
|
+
Rails 5.0
|
103
|
+
Rails 6.0
|
88
104
|
|
89
105
|
## Credits
|
90
106
|
- This code is heavily based upon: [lisinge/valid_email2](https://github.com/lisinge/valid_email2)
|
data/SECURITY.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Security Policy
|
2
|
+
|
3
|
+
## Supported Versions
|
4
|
+
|
5
|
+
Use this section to tell people about which versions of your project are
|
6
|
+
currently being supported with security updates.
|
7
|
+
|
8
|
+
| Version | Supported |
|
9
|
+
| ------- | ------------------ |
|
10
|
+
| 1.0.2 | :white_check_mark: |
|
11
|
+
| 1.0.1 | :x: |
|
12
|
+
| 1.0.0 | :x: |
|
13
|
+
|
14
|
+
|
data/email_check.gemspec
CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.required_ruby_version = ">= 2.0.0"
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "~>
|
25
|
-
spec.add_development_dependency "rake", "~>
|
24
|
+
spec.add_development_dependency "bundler", "~> 2.3"
|
25
|
+
spec.add_development_dependency "rake", "~> 12.3.3"
|
26
26
|
spec.add_development_dependency "rspec","~> 3.2"
|
27
27
|
spec.add_development_dependency "simplecov", "~> 0.10.0"
|
28
28
|
spec.add_development_dependency "coveralls", "~> 0.8.1"
|
@@ -17,19 +17,19 @@ module EmailCheck
|
|
17
17
|
EmailCheck.disposable_email_domains.include?(@email.domain)
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def free_email_provider?
|
21
21
|
EmailCheck.free_email_domains.include?(@email.domain)
|
22
22
|
end
|
23
23
|
|
24
|
-
def
|
24
|
+
def blacklisted_domain?
|
25
25
|
EmailCheck.blacklisted_domains.each do |domain|
|
26
|
-
return true if @email.domain
|
26
|
+
return true if @email.domain&.include?(domain)
|
27
27
|
end
|
28
28
|
|
29
29
|
false
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
32
|
+
def whitelisted_domain?
|
33
33
|
EmailCheck.whitelisted_domains.include?(@email.domain)
|
34
34
|
end
|
35
35
|
|
@@ -39,10 +39,11 @@ module EmailCheck
|
|
39
39
|
|
40
40
|
def domain_has_mx?
|
41
41
|
return false unless format_valid?
|
42
|
-
|
42
|
+
val = false
|
43
43
|
Resolv::DNS.open do |dns|
|
44
|
-
|
44
|
+
val = dns.getresources(@email.domain, Resolv::DNS::Resource::IN::MX).any?
|
45
45
|
end
|
46
|
+
return val
|
46
47
|
end
|
47
48
|
|
48
49
|
private
|
@@ -1,40 +1,54 @@
|
|
1
1
|
require 'active_model'
|
2
2
|
require 'active_model/validations'
|
3
3
|
require 'email_check/email_address'
|
4
|
+
require 'pp'
|
4
5
|
|
5
6
|
class EmailValidator < ActiveModel::EachValidator
|
6
7
|
def validate_each(record, attribute, value)
|
7
|
-
error(record, attribute) unless value.present?
|
8
8
|
|
9
|
-
|
9
|
+
unless value.present?
|
10
|
+
add_error(record, attribute)
|
11
|
+
return
|
12
|
+
end
|
10
13
|
|
11
|
-
|
14
|
+
address = EmailCheck::EmailAddress.new(value)
|
12
15
|
|
13
|
-
|
16
|
+
unless address && address.format_valid?
|
17
|
+
add_error(record, attribute)
|
18
|
+
return
|
19
|
+
end
|
14
20
|
|
15
|
-
if options[:
|
16
|
-
|
21
|
+
if options[:block_special_usernames] && address.blocked_username?
|
22
|
+
add_error(record, attribute)
|
23
|
+
return
|
17
24
|
end
|
18
25
|
|
19
|
-
if
|
20
|
-
|
26
|
+
return if address.whitelisted_domain?
|
27
|
+
|
28
|
+
if options[:not_disposable] && address.disposable?
|
29
|
+
add_error(record, attribute)
|
30
|
+
return
|
21
31
|
end
|
22
32
|
|
23
|
-
if options[:
|
24
|
-
|
33
|
+
if options[:not_blacklisted] && address.blacklisted_domain?
|
34
|
+
add_error(record, attribute)
|
35
|
+
return
|
25
36
|
end
|
26
37
|
|
27
|
-
if options[:
|
28
|
-
|
38
|
+
if options[:not_free] && address.free_email_provider?
|
39
|
+
add_error(record, attribute)
|
40
|
+
return
|
29
41
|
end
|
30
42
|
|
31
|
-
if
|
32
|
-
|
43
|
+
# TODO: Add a callback to bypass this if the domain is already known
|
44
|
+
if options[:check_mx] && address.domain_has_mx? == false
|
45
|
+
add_error(record, attribute)
|
46
|
+
return
|
33
47
|
end
|
34
48
|
end
|
35
49
|
|
36
50
|
private
|
37
|
-
def
|
51
|
+
def add_error(record, attribute)
|
38
52
|
record.errors.add(attribute, options[:message] || :invalid)
|
39
53
|
end
|
40
54
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module ActiveModel
|
2
|
+
module Validations
|
3
|
+
module HelperMethods
|
4
|
+
# Validates email
|
5
|
+
#
|
6
|
+
# Configuration options:
|
7
|
+
# * <tt>:check_mx</tt> - Check MX record for domain
|
8
|
+
# * <tt>:not_disposable</tt> - Check that this is not a disposable email
|
9
|
+
# * <tt>:not_free</tt> - Not a free email (ex. gmail.com, hotmail.com)
|
10
|
+
# * <tt>:not_blacklisted</tt> - If domain is on the blacklist, reject it
|
11
|
+
# * <tt>:block_special_usernames</tt> - If the username is one of the special usernames, reject it
|
12
|
+
def validates_email(*attr_names)
|
13
|
+
validates_with EmailValidator, _merge_attributes(attr_names)
|
14
|
+
end
|
15
|
+
|
16
|
+
# Turn everything on..
|
17
|
+
def validates_email_strictness(*attr_names)
|
18
|
+
validates_with EmailValidator, _merge_attributes(attr_names).merge(
|
19
|
+
:check_mx => true,
|
20
|
+
:not_disposable => true,
|
21
|
+
:not_free => true,
|
22
|
+
:not_blacklisted => true,
|
23
|
+
:block_special_usernames => true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/email_check/version.rb
CHANGED
data/lib/email_check.rb
CHANGED
data/vendor/blacklist.yml
CHANGED