devise-cloudflare-turnstile 0.12.0 → 0.12.1
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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 471aea45843200703b848a8aacef060af2362f7103fae9f417df4f9e092bae12
|
|
4
|
+
data.tar.gz: a33a85702790274610f4580978a446037f5c468680a0128517105d14f58d9061
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b4ada2a98896212e2b0d0c60ac5f81cbf0c56cd204c026273617eefec30aece67b114f6809d2cf81261876c6ac77c4348972dbd0abd48f3e3c7d7794697bc9da
|
|
7
|
+
data.tar.gz: e57e4598eec7ea12bfbad15dfe25855322e0b9d48cef81114b49ef5b66115c6e063f8c7b9bc28a68a5e29390a4c54c58aaf3f7eabc5eeebc000170d059ee55a9
|
|
@@ -10,6 +10,7 @@ module Devise
|
|
|
10
10
|
class_attribute :_turnstile_skip_rules, instance_accessor: false
|
|
11
11
|
self._turnstile_skip_rules = []
|
|
12
12
|
|
|
13
|
+
prepend_before_action :prevalidate_cloudflare_turnstile!, if: :turnstile_verify_action?
|
|
13
14
|
before_action :verify_cloudflare_turnstile!, if: :turnstile_verify_action?
|
|
14
15
|
before_action :set_turnstile_page_marker, if: :turnstile_form_action?
|
|
15
16
|
end
|
|
@@ -30,13 +31,20 @@ module Devise
|
|
|
30
31
|
|
|
31
32
|
private
|
|
32
33
|
|
|
33
|
-
|
|
34
|
+
# Runs ahead of the application's own filters, since any filter that
|
|
35
|
+
# reads the signed-in user lets Warden authenticate from the posted
|
|
36
|
+
# credentials. verify_cloudflare_turnstile! still renders the failure.
|
|
37
|
+
def prevalidate_cloudflare_turnstile!
|
|
38
|
+
return unless turnstile_devise_resource?
|
|
34
39
|
return if turnstile_skipped?
|
|
40
|
+
return if turnstile_verified?
|
|
35
41
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
42
|
+
revoke_params_authentication!
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def verify_cloudflare_turnstile!
|
|
46
|
+
return if turnstile_skipped?
|
|
47
|
+
return if turnstile_verified?
|
|
40
48
|
|
|
41
49
|
revoke_params_authentication!
|
|
42
50
|
restore_turnstile_submitted_values
|
|
@@ -46,10 +54,25 @@ module Devise
|
|
|
46
54
|
render turnstile_failure_action, status: :unprocessable_entity
|
|
47
55
|
end
|
|
48
56
|
|
|
57
|
+
# Memoised because Cloudflare tokens are single use, so the early check
|
|
58
|
+
# and a direct verify_cloudflare_turnstile! call verify only once.
|
|
59
|
+
def turnstile_verified?
|
|
60
|
+
return @_turnstile_verified unless @_turnstile_verified.nil?
|
|
61
|
+
|
|
62
|
+
self.resource ||= resource_class.new
|
|
63
|
+
# No model is passed, so the failure stays out of resource.errors and is
|
|
64
|
+
# reported through the flash, scoped to the render that follows.
|
|
65
|
+
@_turnstile_verified = valid_turnstile?(flash: :now, **turnstile_verify_options)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Devise asserts the mapping in its own prepended callback, which runs
|
|
69
|
+
# after ours. Standing down without one keeps its clearer error.
|
|
70
|
+
def turnstile_devise_resource?
|
|
71
|
+
!respond_to?(:devise_mapping, true) || !devise_mapping.nil?
|
|
72
|
+
end
|
|
73
|
+
|
|
49
74
|
# Devise's sessions#create marks the request eligible for authentication
|
|
50
|
-
#
|
|
51
|
-
# any current_user call during the failure render would sign the visitor
|
|
52
|
-
# in. Devise publishes no constant for the key.
|
|
75
|
+
# from the posted credentials, and publishes no constant for the key.
|
|
53
76
|
def revoke_params_authentication!
|
|
54
77
|
request.env.delete('devise.allow_params_authentication')
|
|
55
78
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: devise-cloudflare-turnstile
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.12.
|
|
4
|
+
version: 0.12.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Vadim Kononov
|
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
79
79
|
- !ruby/object:Gem::Version
|
|
80
80
|
version: '0'
|
|
81
81
|
requirements: []
|
|
82
|
-
rubygems_version:
|
|
82
|
+
rubygems_version: 4.0.10
|
|
83
83
|
specification_version: 4
|
|
84
84
|
summary: Cloudflare Turnstile integration for Devise
|
|
85
85
|
test_files: []
|