recaptcha 5.17.0 → 5.18.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/CHANGELOG.md +1 -0
- data/README.md +8 -6
- data/lib/recaptcha/adapters/controller_methods.rb +22 -1
- data/lib/recaptcha/helpers.rb +1 -0
- data/lib/recaptcha/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 41990aba0d4786ebf87da392ac025d8725d5ca5f30c9e1018b0cf2197f8efada
|
|
4
|
+
data.tar.gz: 34b8d6b1dc5e34d9349c64f3a2d2c77f0cc67b2570077788e9e128d2a855a927
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b3d440a27b41351c81ca9ad94368ea5485d1a1bed05092c011bbfe358cb8c829e89bc295a52a0e323333fc1a3135384149bd3ec13f0cd4c6a8fcc09184a3d4d4
|
|
7
|
+
data.tar.gz: f176ce1beb9764f342dedc8c36cbc40b248ae230c758f2df3053c891c5616b4898e435fde8251da03ff5e690b535bef64bdc7e2257aadc8755f7f0e4efbddbfd
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -78,9 +78,9 @@ export RECAPTCHA_ENTERPRISE_API_KEY = 'AIzvFyE3TU-g4K_Kozr9F1smEzZSGBVOfLKyup
|
|
|
78
78
|
export RECAPTCHA_ENTERPRISE_PROJECT_ID = 'my-project'
|
|
79
79
|
```
|
|
80
80
|
|
|
81
|
-
_note:_ you'll still have to provide `RECAPTCHA_SITE_KEY`, which will hold the value of your enterprise recaptcha key id. You will not need to provide a `RECAPTCHA_SECRET_KEY`, however.
|
|
81
|
+
_note:_ you'll still have to provide `RECAPTCHA_SITE_KEY`, which will hold the value of your enterprise recaptcha key id. You will not need to provide a `RECAPTCHA_SECRET_KEY`, however.
|
|
82
82
|
|
|
83
|
-
`RECAPTCHA_ENTERPRISE_API_KEY` is the enterprise key of your Google Cloud Project, which you can generate here: https://console.cloud.google.com/apis/credentials.
|
|
83
|
+
`RECAPTCHA_ENTERPRISE_API_KEY` is the enterprise key of your Google Cloud Project, which you can generate here: https://console.cloud.google.com/apis/credentials.
|
|
84
84
|
|
|
85
85
|
Add `recaptcha_tags` to the forms you want to protect:
|
|
86
86
|
|
|
@@ -130,7 +130,7 @@ The following options are available:
|
|
|
130
130
|
| `:site_key` | Override site API key from configuration |
|
|
131
131
|
| `:error` | Override the error code returned from the reCAPTCHA API (default: `nil`) |
|
|
132
132
|
| `:size` | Specify a size (default: `nil`) |
|
|
133
|
-
| `:nonce` | Optional. Sets nonce attribute for script. Can be generated via `SecureRandom.base64(32)`. (default: `nil`) |
|
|
133
|
+
| `:nonce` | Optional. Sets nonce attribute for script. Can be generated via `SecureRandom.base64(32)`. Use `content_security_policy_nonce` if you have `config.content_security_policy_nonce_generator` set in Rails. (default: `nil`) |
|
|
134
134
|
| `:id` | Specify an html id attribute (default: `nil`) |
|
|
135
135
|
| `:callback` | Optional. Name of success callback function, executed when the user submits a successful response |
|
|
136
136
|
| `:expired_callback` | Optional. Name of expiration callback function, executed when the reCAPTCHA response expires and the user needs to re-verify. |
|
|
@@ -208,7 +208,7 @@ It also accepts most of the options that `recaptcha_tags` accepts, including the
|
|
|
208
208
|
| Option | Description |
|
|
209
209
|
|---------------------|-------------|
|
|
210
210
|
| `:site_key` | Override site API key from configuration |
|
|
211
|
-
| `:nonce` | Optional. Sets nonce attribute for script tag. Can be generated via `SecureRandom.base64(32)`. (default: `nil`) |
|
|
211
|
+
| `:nonce` | Optional. Sets nonce attribute for script tag. Can be generated via `SecureRandom.base64(32)`. Use `content_security_policy_nonce` if you have `config.content_security_policy_nonce_generator` set in Rails. (default: `nil`) |
|
|
212
212
|
| `:id` | Specify an html id attribute (default: `nil`) |
|
|
213
213
|
| `:script` | Same as setting both `:inline_script` and `:external_script`. If you only need one or the other, use `:inline_script` and `:external_script` instead. |
|
|
214
214
|
| `:callback` | Optional. Name of success callback function, executed when the user submits a successful response |
|
|
@@ -432,7 +432,7 @@ but only accepts the following options:
|
|
|
432
432
|
|---------------------|-------------|
|
|
433
433
|
| `:site_key` | Override site API key |
|
|
434
434
|
| `:action` | The name of the [reCAPTCHA action](https://developers.google.com/recaptcha/docs/v3#actions). Actions are not case-sensitive and may only contain alphanumeric characters, slashes, and underscores, and must not be user-specific. |
|
|
435
|
-
| `:nonce` | Optional. Sets nonce attribute for script. Can be generated via `SecureRandom.base64(32)`. (default: `nil`) |
|
|
435
|
+
| `:nonce` | Optional. Sets nonce attribute for script. Can be generated via `SecureRandom.base64(32)`. Use `content_security_policy_nonce` if you have `config.content_security_policy_nonce_generator` set in Rails. (default: `nil`) |
|
|
436
436
|
| `:callback` | Name of callback function to call with the token. When `element` is `:input`, this defaults to a function named `setInputWithRecaptchaResponseTokenFor#{sanitize_action(action)}` that sets the value of the hidden input to the token. |
|
|
437
437
|
| `:id` | Specify a unique `id` attribute for the `<input>` element if using `element: :input`. (default: `"g-recaptcha-response-data-"` + `action`) |
|
|
438
438
|
| `:name` | Specify a unique `name` attribute for the `<input>` element if using `element: :input`. (default: `g-recaptcha-response-data[action]`) |
|
|
@@ -488,7 +488,7 @@ are passed as a hash under `params['g-recaptcha-response-data']` with the action
|
|
|
488
488
|
It is recommended to pass `external_script: false` on all but one of the calls to
|
|
489
489
|
`recaptcha` since you only need to include the script tag once for a given `site_key`.
|
|
490
490
|
|
|
491
|
-
## `recaptcha_reply`
|
|
491
|
+
## `recaptcha_reply` and `recaptcha_failure_reason`
|
|
492
492
|
|
|
493
493
|
After `verify_recaptcha` has been called, you can call `recaptcha_reply` to get the raw reply from recaptcha. This can allow you to get the exact score returned by recaptcha should you need it.
|
|
494
494
|
|
|
@@ -504,6 +504,8 @@ end
|
|
|
504
504
|
|
|
505
505
|
`recaptcha_reply` will return `nil` if the the reply was not yet fetched.
|
|
506
506
|
|
|
507
|
+
`recaptcha_failure_reason` will return information if verification failed. E.g. if params was wrong or api resulted some error-codes.
|
|
508
|
+
|
|
507
509
|
## I18n support
|
|
508
510
|
|
|
509
511
|
reCAPTCHA supports the I18n gem (it comes with English translations)
|
|
@@ -17,6 +17,11 @@ module Recaptcha
|
|
|
17
17
|
|
|
18
18
|
begin
|
|
19
19
|
verified = if Recaptcha.invalid_response?(recaptcha_response)
|
|
20
|
+
@_recaptcha_failure_reason = if recaptcha_response.nil?
|
|
21
|
+
"No recaptcha response/param(:action) found."
|
|
22
|
+
else
|
|
23
|
+
"Recaptcha response/param(:action) was invalid."
|
|
24
|
+
end
|
|
20
25
|
false
|
|
21
26
|
else
|
|
22
27
|
unless options[:skip_remote_ip]
|
|
@@ -26,10 +31,21 @@ module Recaptcha
|
|
|
26
31
|
|
|
27
32
|
success, @_recaptcha_reply =
|
|
28
33
|
Recaptcha.verify_via_api_call(recaptcha_response, options.merge(with_reply: true))
|
|
34
|
+
unless success
|
|
35
|
+
@_recaptcha_failure_reason = if @_recaptcha_reply["score"] &&
|
|
36
|
+
@_recaptcha_reply["score"].to_f < options[:minimum_score].to_f
|
|
37
|
+
"Recaptcha score didn't exceed the minimum: #{@_recaptcha_reply["score"]} < #{options[:minimum_score]}."
|
|
38
|
+
elsif @_recaptcha_reply['error-codes']
|
|
39
|
+
"Recaptcha api call returned with error-codes: #{@_recaptcha_reply['error-codes']}."
|
|
40
|
+
else
|
|
41
|
+
"Recaptcha failure after api call. Api reply: #{@_recaptcha_reply}."
|
|
42
|
+
end
|
|
43
|
+
end
|
|
29
44
|
success
|
|
30
45
|
end
|
|
31
46
|
|
|
32
47
|
if verified
|
|
48
|
+
@_recaptcha_failure_reason = nil
|
|
33
49
|
flash.delete(:recaptcha_error) if recaptcha_flash_supported? && !model
|
|
34
50
|
true
|
|
35
51
|
else
|
|
@@ -41,6 +57,7 @@ module Recaptcha
|
|
|
41
57
|
false
|
|
42
58
|
end
|
|
43
59
|
rescue Timeout::Error
|
|
60
|
+
@_recaptcha_failure_reason = "Recaptcha server unreachable."
|
|
44
61
|
if Recaptcha.configuration.handle_timeouts_gracefully
|
|
45
62
|
recaptcha_error(
|
|
46
63
|
model,
|
|
@@ -57,13 +74,17 @@ module Recaptcha
|
|
|
57
74
|
end
|
|
58
75
|
|
|
59
76
|
def verify_recaptcha!(options = {})
|
|
60
|
-
verify_recaptcha(options) || raise(VerifyError)
|
|
77
|
+
verify_recaptcha(options) || raise(VerifyError, @_recaptcha_failure_reason)
|
|
61
78
|
end
|
|
62
79
|
|
|
63
80
|
def recaptcha_reply
|
|
64
81
|
@_recaptcha_reply if defined?(@_recaptcha_reply)
|
|
65
82
|
end
|
|
66
83
|
|
|
84
|
+
def recaptcha_failure_reason
|
|
85
|
+
@_recaptcha_failure_reason
|
|
86
|
+
end
|
|
87
|
+
|
|
67
88
|
def recaptcha_error(model, attribute, message)
|
|
68
89
|
if model
|
|
69
90
|
model.errors.add(attribute, message)
|
data/lib/recaptcha/helpers.rb
CHANGED
|
@@ -140,6 +140,7 @@ module Recaptcha
|
|
|
140
140
|
skip_script = (options.delete(:script) == false) || (options.delete(:external_script) == false)
|
|
141
141
|
ui = options.delete(:ui)
|
|
142
142
|
options.delete(:ignore_no_element)
|
|
143
|
+
options.delete(:inline_script)
|
|
143
144
|
|
|
144
145
|
data_attribute_keys = [:badge, :theme, :type, :callback, :expired_callback, :error_callback, :size]
|
|
145
146
|
data_attribute_keys << :tabindex unless ui == :button
|
data/lib/recaptcha/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: recaptcha
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.
|
|
4
|
+
version: 5.18.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Jason L Perry
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-12-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: mocha
|