recaptcha 5.17.1 → 5.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +6 -3
- data/lib/recaptcha/adapters/controller_methods.rb +22 -1
- data/lib/recaptcha/configuration.rb +5 -2
- data/lib/recaptcha/version.rb +1 -1
- data/lib/recaptcha.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: 61fa7316f287cfcec8e2b06d36481f1fa596d1b629810a784fae509c55255b2f
|
4
|
+
data.tar.gz: 7cf82254973204d7ac47b6bba428ff394e24c9ec5dbbb5669657b4c10b30c16b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 572402b7af72a67f76a1952cb7e5739a7cf4073ba0b510f55f8f74bc59a6e6116bad1be5ece41e20a43cb2d3c36c7ab2bca072b8a4c27b5a1db16d1007846284
|
7
|
+
data.tar.gz: 021a0fa67e25aee448c66c43ae5fd3295d1472329bccdcfe4a5acf2c6fe90fd83c9cdcf8963db29816919fb6383d49c8303d41032e1af8abde3dcafbdeacc36a
|
data/CHANGELOG.md
CHANGED
@@ -1,9 +1,17 @@
|
|
1
1
|
## Next
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
## 5.19.0
|
6
|
+
* require a minimum lenght of 100 for responses, configured via response_minimum
|
7
|
+
|
8
|
+
## 5.18.0
|
2
9
|
* Add key setup to v3 example in README
|
3
10
|
* Remove unnecessary id from textarea - This was unused and may cause accessability concerns if there is more than one recaptcha on the page due to multiple elements with the same id
|
4
11
|
* Update to latest version of rubocop
|
5
12
|
* Drop support for Ruby 2.7; add Ruby 3.3
|
6
13
|
* Add i18n: de, es, it, pt, pt-BR
|
14
|
+
* Added recaptcha_failure_reason
|
7
15
|
|
8
16
|
## 5.16.0
|
9
17
|
* Allow usage of `options[:turbo]` as well as `options[:turbolinks]` for `recaptcha_v3`
|
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
|
|
@@ -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)
|
@@ -587,6 +589,7 @@ Recaptcha.configure do |config|
|
|
587
589
|
config.verify_url = 'https://hcaptcha.com/siteverify'
|
588
590
|
config.api_server_url = 'https://hcaptcha.com/1/api.js'
|
589
591
|
config.response_limit = 100000
|
592
|
+
config.response_minimum = 100
|
590
593
|
end
|
591
594
|
```
|
592
595
|
|
@@ -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)
|
@@ -37,8 +37,10 @@ module Recaptcha
|
|
37
37
|
'enterprise_verify_url' => 'https://recaptchaenterprise.googleapis.com/v1/projects'
|
38
38
|
}.freeze
|
39
39
|
|
40
|
-
attr_accessor
|
41
|
-
|
40
|
+
attr_accessor(
|
41
|
+
:default_env, :skip_verify_env, :proxy, :secret_key, :site_key, :handle_timeouts_gracefully,
|
42
|
+
:hostname, :enterprise, :enterprise_api_key, :enterprise_project_id, :response_limit, :response_minimum
|
43
|
+
)
|
42
44
|
attr_writer :api_server_url, :verify_url
|
43
45
|
|
44
46
|
def initialize # :nodoc:
|
@@ -57,6 +59,7 @@ module Recaptcha
|
|
57
59
|
@api_server_url = nil
|
58
60
|
|
59
61
|
@response_limit = 4000
|
62
|
+
@response_minimum = 100
|
60
63
|
end
|
61
64
|
|
62
65
|
def secret_key!
|
data/lib/recaptcha/version.rb
CHANGED
data/lib/recaptcha.rb
CHANGED
@@ -55,7 +55,7 @@ module Recaptcha
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def self.invalid_response?(resp)
|
58
|
-
resp.empty? || resp.length > configuration.response_limit
|
58
|
+
resp.empty? || resp.length > configuration.response_limit || resp.length < configuration.response_minimum
|
59
59
|
end
|
60
60
|
|
61
61
|
def self.verify_via_api_call(response, options)
|
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.19.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:
|
11
|
+
date: 2025-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mocha
|