devise-two-factor 6.1.0 → 6.2.0
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 +4 -4
- data/.github/workflows/ci.yml +7 -3
- data/.github/workflows/push.yml +1 -1
- data/Appraisals +5 -0
- data/CHANGELOG.md +8 -0
- data/README.md +4 -7
- data/devise-two-factor.gemspec +2 -2
- data/gemfiles/rails_8.1.gemfile +8 -0
- data/lib/devise-two-factor.rb +1 -0
- data/lib/devise_two_factor/models/two_factor_authenticatable.rb +9 -12
- data/lib/devise_two_factor/strategies/two_factor_backupable.rb +6 -1
- data/lib/devise_two_factor/version.rb +1 -1
- metadata +8 -11
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b6893a24ebfb4eae935305d8b0657383c1630eb7619e23dfcd9ad0190bf1cd64
|
|
4
|
+
data.tar.gz: 24bab113bff7ae25afd03f9230caf372f8bdb0c319eeb18ab469353ca5136de1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0b78eedcbafc38b967fb8a6717b9f70f87751b234ce905f5b4d99a176224e4927bc7039a69bb454daba16c8b07b368dc1d9a89e19016910733fd5f744f857a7c
|
|
7
|
+
data.tar.gz: '0199a55f34cc5b67375620c1acabbca8b7256ead8b5401a6917dc2589b64158080851c9d5a061bc7fba1b95d36034f4e24aa13f1efb802a9cf44d1e202f407a0'
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -12,17 +12,21 @@ jobs:
|
|
|
12
12
|
fail-fast: false
|
|
13
13
|
matrix:
|
|
14
14
|
# Due to https://github.com/actions/runner/issues/849, we should quote versions
|
|
15
|
-
ruby: ['3.1', '3.2', '3.3', 'truffleruby-head']
|
|
16
|
-
rails: ['7.0', '7.1', '7.2', '8.0']
|
|
15
|
+
ruby: ['3.1', '3.2', '3.3', '3.4', 'truffleruby-head']
|
|
16
|
+
rails: ['7.0', '7.1', '7.2', '8.0', '8.1']
|
|
17
17
|
exclude:
|
|
18
18
|
- ruby: '3.1'
|
|
19
19
|
rails: '8.0'
|
|
20
|
+
- ruby: '3.1'
|
|
21
|
+
rails: '8.1'
|
|
22
|
+
- ruby: '3.4'
|
|
23
|
+
rails: '7.0'
|
|
20
24
|
|
|
21
25
|
name: Ruby ${{ matrix.ruby }}, Rails ${{ matrix.rails }}
|
|
22
26
|
env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps
|
|
23
27
|
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_${{ matrix.rails }}.gemfile
|
|
24
28
|
steps:
|
|
25
|
-
- uses: actions/checkout@
|
|
29
|
+
- uses: actions/checkout@v5
|
|
26
30
|
- name: Set up Ruby
|
|
27
31
|
uses: ruby/setup-ruby@v1
|
|
28
32
|
with:
|
data/.github/workflows/push.yml
CHANGED
data/Appraisals
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -82,7 +82,7 @@ This generator will:
|
|
|
82
82
|
|
|
83
83
|
1. Edit `app/models/MODEL.rb` (where MODEL is your model name):
|
|
84
84
|
* add the `:two_factor_authenticatable` devise module
|
|
85
|
-
* remove the `:database_authenticatable` if present
|
|
85
|
+
* remove the `:database_authenticatable` devise module, if present; having both modules enabled will lead to issues described below.
|
|
86
86
|
1. Add a Warden config block to your Devise initializer, which enables the strategies required for two-factor authentication.
|
|
87
87
|
|
|
88
88
|
Remember to apply the new migration after you run the generator:
|
|
@@ -107,9 +107,9 @@ Next you need to whitelist `:otp_attempt` as a permitted parameter in Devise `:s
|
|
|
107
107
|
end
|
|
108
108
|
```
|
|
109
109
|
|
|
110
|
-
Finally you should verify that `:database_authenticatable` is **not** being loaded by your model. The generator will try to remove it, but if you have a non-standard Devise setup, this step may fail.
|
|
110
|
+
Finally you should verify that `:database_authenticatable` is **not** being loaded by your model. The generator will try to remove it, but if you have a non-standard Devise setup, this step may fail. `:two_factor_authenticatable` includes all of `:database_authenticatable`'s functionality; it will still allow login without two-factor authentication until you enable it on your model's records with `otp_required_for_login`.
|
|
111
111
|
|
|
112
|
-
**Loading both `:database_authenticatable` and `:two_factor_authenticatable` in a model is a security issue
|
|
112
|
+
**Loading both `:database_authenticatable` and `:two_factor_authenticatable` in a model is a security issue.** It will allow users to bypass two-factor authentication regardless of how `otp_required_for_login` is set due to the way Warden handles cascading strategies!
|
|
113
113
|
|
|
114
114
|
## Designing Your Workflow
|
|
115
115
|
|
|
@@ -155,10 +155,7 @@ At Tinfoil Security, we opted to use the excellent [rqrcode-rails3](https://gith
|
|
|
155
155
|
If you decide to do this you'll need to generate a URI to act as the source for the QR code. This can be done using the `User#otp_provisioning_uri` method.
|
|
156
156
|
|
|
157
157
|
```ruby
|
|
158
|
-
issuer
|
|
159
|
-
label = "#{issuer}:#{current_user.email}"
|
|
160
|
-
|
|
161
|
-
current_user.otp_provisioning_uri(label, issuer: issuer)
|
|
158
|
+
current_user.otp_provisioning_uri(current_user.email, issuer: 'Your App')
|
|
162
159
|
|
|
163
160
|
# > "otpauth://totp/Your%20App:user@example.com?secret=[otp_secret]&issuer=Your+App"
|
|
164
161
|
```
|
data/devise-two-factor.gemspec
CHANGED
|
@@ -15,8 +15,8 @@ Gem::Specification.new do |s|
|
|
|
15
15
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
|
16
16
|
s.require_paths = ['lib']
|
|
17
17
|
|
|
18
|
-
s.add_runtime_dependency 'railties', '>= 7.0', '< 8.
|
|
19
|
-
s.add_runtime_dependency 'activesupport', '>= 7.0', '< 8.
|
|
18
|
+
s.add_runtime_dependency 'railties', '>= 7.0', '< 8.2'
|
|
19
|
+
s.add_runtime_dependency 'activesupport', '>= 7.0', '< 8.2'
|
|
20
20
|
s.add_runtime_dependency 'devise', '~> 4.0'
|
|
21
21
|
s.add_runtime_dependency 'rotp', '~> 6.0'
|
|
22
22
|
|
data/lib/devise-two-factor.rb
CHANGED
|
@@ -41,12 +41,11 @@ module Devise
|
|
|
41
41
|
|
|
42
42
|
if self.consumed_timestep
|
|
43
43
|
# reconstruct the timestamp of the last consumed timestep
|
|
44
|
-
after_timestamp = self.consumed_timestep *
|
|
44
|
+
after_timestamp = self.consumed_timestep * totp.interval
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
end
|
|
47
|
+
timestamp = totp.verify(code.gsub(/\s+/, ""), drift_behind: self.class.otp_allowed_drift, drift_ahead: self.class.otp_allowed_drift, after: after_timestamp)
|
|
48
|
+
return consume_otp!(totp, timestamp) if timestamp
|
|
50
49
|
|
|
51
50
|
false
|
|
52
51
|
end
|
|
@@ -59,11 +58,6 @@ module Devise
|
|
|
59
58
|
otp.at(Time.now)
|
|
60
59
|
end
|
|
61
60
|
|
|
62
|
-
# ROTP's TOTP#timecode is private, so we duplicate it here
|
|
63
|
-
def current_otp_timestep
|
|
64
|
-
Time.now.utc.to_i / otp.interval
|
|
65
|
-
end
|
|
66
|
-
|
|
67
61
|
def otp_provisioning_uri(account, options = {})
|
|
68
62
|
otp_secret = options[:otp_secret] || self.otp_secret
|
|
69
63
|
ROTP::TOTP.new(otp_secret, options).provisioning_uri(account)
|
|
@@ -78,10 +72,13 @@ module Devise
|
|
|
78
72
|
|
|
79
73
|
# An OTP cannot be used more than once in a given timestep
|
|
80
74
|
# Storing timestep of last valid OTP is sufficient to satisfy this requirement
|
|
81
|
-
def consume_otp!
|
|
82
|
-
|
|
83
|
-
|
|
75
|
+
def consume_otp!(otp, timestamp)
|
|
76
|
+
timestep = timestamp / otp.interval
|
|
77
|
+
|
|
78
|
+
if self.consumed_timestep != timestep
|
|
79
|
+
self.consumed_timestep = timestep
|
|
84
80
|
save!(validate: false)
|
|
81
|
+
|
|
85
82
|
return true
|
|
86
83
|
end
|
|
87
84
|
|
|
@@ -5,7 +5,7 @@ module Devise
|
|
|
5
5
|
def authenticate!
|
|
6
6
|
resource = mapping.to.find_for_database_authentication(authentication_hash)
|
|
7
7
|
|
|
8
|
-
if validate(resource) { resource
|
|
8
|
+
if validate(resource) { validate_backup_code(resource) }
|
|
9
9
|
super
|
|
10
10
|
end
|
|
11
11
|
|
|
@@ -15,6 +15,11 @@ module Devise
|
|
|
15
15
|
# but database authenticatable automatically halts on a bad password
|
|
16
16
|
@halted = false if @result == :failure
|
|
17
17
|
end
|
|
18
|
+
|
|
19
|
+
def validate_backup_code(resource)
|
|
20
|
+
return if params[scope].nil? || params[scope]['otp_attempt'].nil?
|
|
21
|
+
resource.invalidate_otp_backup_code!(params[scope]['otp_attempt'])
|
|
22
|
+
end
|
|
18
23
|
end
|
|
19
24
|
end
|
|
20
25
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: devise-two-factor
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.
|
|
4
|
+
version: 6.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Quinn Wilton
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2025-10-22 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: railties
|
|
@@ -19,7 +18,7 @@ dependencies:
|
|
|
19
18
|
version: '7.0'
|
|
20
19
|
- - "<"
|
|
21
20
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '8.
|
|
21
|
+
version: '8.2'
|
|
23
22
|
type: :runtime
|
|
24
23
|
prerelease: false
|
|
25
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -29,7 +28,7 @@ dependencies:
|
|
|
29
28
|
version: '7.0'
|
|
30
29
|
- - "<"
|
|
31
30
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '8.
|
|
31
|
+
version: '8.2'
|
|
33
32
|
- !ruby/object:Gem::Dependency
|
|
34
33
|
name: activesupport
|
|
35
34
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -39,7 +38,7 @@ dependencies:
|
|
|
39
38
|
version: '7.0'
|
|
40
39
|
- - "<"
|
|
41
40
|
- !ruby/object:Gem::Version
|
|
42
|
-
version: '8.
|
|
41
|
+
version: '8.2'
|
|
43
42
|
type: :runtime
|
|
44
43
|
prerelease: false
|
|
45
44
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -49,7 +48,7 @@ dependencies:
|
|
|
49
48
|
version: '7.0'
|
|
50
49
|
- - "<"
|
|
51
50
|
- !ruby/object:Gem::Version
|
|
52
|
-
version: '8.
|
|
51
|
+
version: '8.2'
|
|
53
52
|
- !ruby/object:Gem::Dependency
|
|
54
53
|
name: devise
|
|
55
54
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -164,7 +163,6 @@ dependencies:
|
|
|
164
163
|
version: '13'
|
|
165
164
|
description: Devise-Two-Factor is a minimalist extension to Devise which offers support
|
|
166
165
|
for two-factor authentication through the TOTP scheme.
|
|
167
|
-
email:
|
|
168
166
|
executables: []
|
|
169
167
|
extensions: []
|
|
170
168
|
extra_rdoc_files: []
|
|
@@ -189,6 +187,7 @@ files:
|
|
|
189
187
|
- gemfiles/rails_7.1.gemfile
|
|
190
188
|
- gemfiles/rails_7.2.gemfile
|
|
191
189
|
- gemfiles/rails_8.0.gemfile
|
|
190
|
+
- gemfiles/rails_8.1.gemfile
|
|
192
191
|
- lib/devise-two-factor.rb
|
|
193
192
|
- lib/devise_two_factor/models.rb
|
|
194
193
|
- lib/devise_two_factor/models/two_factor_authenticatable.rb
|
|
@@ -208,7 +207,6 @@ homepage: https://github.com/devise-two-factor/devise-two-factor
|
|
|
208
207
|
licenses:
|
|
209
208
|
- MIT
|
|
210
209
|
metadata: {}
|
|
211
|
-
post_install_message:
|
|
212
210
|
rdoc_options: []
|
|
213
211
|
require_paths:
|
|
214
212
|
- lib
|
|
@@ -223,8 +221,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
223
221
|
- !ruby/object:Gem::Version
|
|
224
222
|
version: '0'
|
|
225
223
|
requirements: []
|
|
226
|
-
rubygems_version: 3.
|
|
227
|
-
signing_key:
|
|
224
|
+
rubygems_version: 3.6.2
|
|
228
225
|
specification_version: 4
|
|
229
226
|
summary: Barebones two-factor authentication with Devise
|
|
230
227
|
test_files:
|