recaptcha 5.8.1 → 5.10.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +34 -0
- data/lib/recaptcha/configuration.rb +6 -4
- data/lib/recaptcha/helpers.rb +1 -1
- data/lib/recaptcha/version.rb +1 -1
- data/lib/recaptcha.rb +15 -17
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c43aec95c9b3af962cc3d9a46c70f85dc0fa3f76c29149cc6f67614aa4d1189
|
4
|
+
data.tar.gz: 5198c7347e482fb4bc0b6263742d719458764db9921b7b374f238e44297eaba7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca84949e30a26d5409192dfdda7919902389b521779edec2d9b1ff70a79ede29cfe77caf015ce418eb61e397fed73140e581c5fb12b2cdea7a4ebddd457ec917
|
7
|
+
data.tar.gz: a9b982cda895842bc2b1096af656805b23d9a76cf480c590e14b1b9cf3a2ef54dd9483b580d6d9cc90060ffe437444c404bec418b1be269bc4c83fcd1090aafa
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -50,6 +50,8 @@ Note: Enter `localhost` or `127.0.0.1` as the domain if using in development wit
|
|
50
50
|
|
51
51
|
## Rails Installation
|
52
52
|
|
53
|
+
**If you are having issues with Rails 7, Turbo, and Stimulus, make sure to check [this Wiki page](https://github.com/ambethia/recaptcha/wiki/Recaptcha-with-Turbo-and-Stimulus)!**
|
54
|
+
|
53
55
|
```ruby
|
54
56
|
gem "recaptcha"
|
55
57
|
```
|
@@ -551,6 +553,38 @@ recaptcha_tags site_key: '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
|
|
551
553
|
verify_recaptcha secret_key: '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
|
552
554
|
```
|
553
555
|
|
556
|
+
|
557
|
+
## hCaptcha support
|
558
|
+
|
559
|
+
[hCaptcha](https://hcaptcha.com) is an alternative service providing reCAPTCHA API.
|
560
|
+
|
561
|
+
To use hCaptcha:
|
562
|
+
1. Set a site and a secret key as usual
|
563
|
+
2. Set two options in `verify_url` and `api_service_url` pointing to hCaptcha API endpoints.
|
564
|
+
3. Disable a response limit check by setting a `response_limit` to the large enough value (reCAPTCHA is limited by 4000 characters).
|
565
|
+
4. It is not required to change a parameter name as [official docs suggest](https://docs.hcaptcha.com/switch) because API handles standard `g-recaptcha` for compatibility.
|
566
|
+
|
567
|
+
```ruby
|
568
|
+
# config/initializers/recaptcha.rb
|
569
|
+
Recaptcha.configure do |config|
|
570
|
+
config.site_key = '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'
|
571
|
+
config.secret_key = '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'
|
572
|
+
config.verify_url = 'https://hcaptcha.com/siteverify'
|
573
|
+
config.api_server_url = 'https://hcaptcha.com/1/api.js'
|
574
|
+
config.response_limit = 100000
|
575
|
+
end
|
576
|
+
```
|
577
|
+
|
578
|
+
hCaptcha uses a scoring system (higher number more likely to be a bot) which is inverse of the reCaptcha scoring system (lower number more likely to be a bot). As such, a `maximum_score` attribute is provided for use with hCaptcha.
|
579
|
+
|
580
|
+
```ruby
|
581
|
+
result = verify_recaptcha(maximum_score: 0.7)
|
582
|
+
```
|
583
|
+
|
584
|
+
| Option | Description |
|
585
|
+
|------------------|-------------|
|
586
|
+
| `:maximum_score` | Provide a threshold to meet or fall below. Threshold should be a float between 0 and 1 which will be tested as `score <= maximum_score`. (Default: `nil`) |
|
587
|
+
|
554
588
|
## Misc
|
555
589
|
- Check out the [wiki](https://github.com/ambethia/recaptcha/wiki) and leave whatever you found valuable there.
|
556
590
|
- [Add multiple widgets to the same page](https://github.com/ambethia/recaptcha/wiki/Add-multiple-widgets-to-the-same-page)
|
@@ -34,14 +34,14 @@ module Recaptcha
|
|
34
34
|
'free_server_url' => 'https://www.recaptcha.net/recaptcha/api.js',
|
35
35
|
'enterprise_server_url' => 'https://www.recaptcha.net/recaptcha/enterprise.js',
|
36
36
|
'free_verify_url' => 'https://www.recaptcha.net/recaptcha/api/siteverify',
|
37
|
-
'enterprise_verify_url' => 'https://recaptchaenterprise.googleapis.com/
|
37
|
+
'enterprise_verify_url' => 'https://recaptchaenterprise.googleapis.com/v1/projects'
|
38
38
|
}.freeze
|
39
39
|
|
40
|
-
attr_accessor :default_env, :skip_verify_env, :proxy, :secret_key, :site_key, :handle_timeouts_gracefully,
|
41
|
-
|
40
|
+
attr_accessor :default_env, :skip_verify_env, :proxy, :secret_key, :site_key, :handle_timeouts_gracefully,
|
41
|
+
:hostname, :enterprise, :enterprise_api_key, :enterprise_project_id, :response_limit
|
42
42
|
attr_writer :api_server_url, :verify_url
|
43
43
|
|
44
|
-
def initialize
|
44
|
+
def initialize # :nodoc:
|
45
45
|
@default_env = ENV['RAILS_ENV'] || ENV['RACK_ENV'] || (Rails.env if defined? Rails.env)
|
46
46
|
@skip_verify_env = %w[test cucumber]
|
47
47
|
@handle_timeouts_gracefully = true
|
@@ -55,6 +55,8 @@ module Recaptcha
|
|
55
55
|
|
56
56
|
@verify_url = nil
|
57
57
|
@api_server_url = nil
|
58
|
+
|
59
|
+
@response_limit = 4000
|
58
60
|
end
|
59
61
|
|
60
62
|
def secret_key!
|
data/lib/recaptcha/helpers.rb
CHANGED
@@ -10,7 +10,7 @@ module Recaptcha
|
|
10
10
|
def self.recaptcha_v3(options = {})
|
11
11
|
site_key = options[:site_key] ||= Recaptcha.configuration.site_key!
|
12
12
|
action = options.delete(:action) || raise(Recaptcha::RecaptchaError, 'action is required')
|
13
|
-
id = options.delete(:id) || "g-recaptcha-response-data
|
13
|
+
id = options.delete(:id) || "g-recaptcha-response-data-#{dasherize_action(action)}"
|
14
14
|
name = options.delete(:name) || "g-recaptcha-response-data[#{action}]"
|
15
15
|
turbolinks = options.delete(:turbolinks)
|
16
16
|
options[:render] = site_key
|
data/lib/recaptcha/version.rb
CHANGED
data/lib/recaptcha.rb
CHANGED
@@ -14,7 +14,6 @@ end
|
|
14
14
|
|
15
15
|
module Recaptcha
|
16
16
|
DEFAULT_TIMEOUT = 3
|
17
|
-
RESPONSE_LIMIT = 4000
|
18
17
|
|
19
18
|
class RecaptchaError < StandardError
|
20
19
|
end
|
@@ -56,7 +55,7 @@ module Recaptcha
|
|
56
55
|
end
|
57
56
|
|
58
57
|
def self.invalid_response?(resp)
|
59
|
-
resp.empty? || resp.length >
|
58
|
+
resp.empty? || resp.length > configuration.response_limit
|
60
59
|
end
|
61
60
|
|
62
61
|
def self.verify_via_api_call(response, options)
|
@@ -83,12 +82,13 @@ module Recaptcha
|
|
83
82
|
token_properties['valid'].to_s == 'true' &&
|
84
83
|
hostname_valid?(token_properties['hostname'], options[:hostname]) &&
|
85
84
|
action_valid?(token_properties['action'], options[:action]) &&
|
86
|
-
score_above_threshold?(reply['score'], options[:minimum_score])
|
85
|
+
score_above_threshold?(reply['score'], options[:minimum_score]) &&
|
86
|
+
score_below_threshold?(reply['score'], options[:maximum_score])
|
87
87
|
|
88
88
|
if options[:with_reply] == true
|
89
|
-
|
89
|
+
[success, reply]
|
90
90
|
else
|
91
|
-
|
91
|
+
success
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
@@ -101,12 +101,13 @@ module Recaptcha
|
|
101
101
|
success = reply['success'].to_s == 'true' &&
|
102
102
|
hostname_valid?(reply['hostname'], options[:hostname]) &&
|
103
103
|
action_valid?(reply['action'], options[:action]) &&
|
104
|
-
score_above_threshold?(reply['score'], options[:minimum_score])
|
104
|
+
score_above_threshold?(reply['score'], options[:minimum_score]) &&
|
105
|
+
score_below_threshold?(reply['score'], options[:maximum_score])
|
105
106
|
|
106
107
|
if options[:with_reply] == true
|
107
|
-
|
108
|
+
[success, reply]
|
108
109
|
else
|
109
|
-
|
110
|
+
success
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
@@ -127,15 +128,12 @@ module Recaptcha
|
|
127
128
|
end
|
128
129
|
end
|
129
130
|
|
130
|
-
# Returns true iff score is greater or equal to (>=) minimum_score, or if no minimum_score was specified
|
131
131
|
def self.score_above_threshold?(score, minimum_score)
|
132
|
-
|
133
|
-
|
132
|
+
!minimum_score || (score && score >= minimum_score)
|
133
|
+
end
|
134
134
|
|
135
|
-
|
136
|
-
|
137
|
-
else score >= minimum_score
|
138
|
-
end
|
135
|
+
def self.score_below_threshold?(score, maximum_score)
|
136
|
+
!maximum_score || (score && score <= maximum_score)
|
139
137
|
end
|
140
138
|
|
141
139
|
def self.http_client_for(uri:, timeout: nil)
|
@@ -155,7 +153,7 @@ module Recaptcha
|
|
155
153
|
|
156
154
|
def self.api_verification_free(verify_hash, timeout: nil)
|
157
155
|
query = URI.encode_www_form(verify_hash)
|
158
|
-
uri = URI.parse(configuration.verify_url
|
156
|
+
uri = URI.parse("#{configuration.verify_url}?#{query}")
|
159
157
|
http_instance = http_client_for(uri: uri, timeout: timeout)
|
160
158
|
request = Net::HTTP::Get.new(uri.request_uri)
|
161
159
|
JSON.parse(http_instance.request(request).body)
|
@@ -163,7 +161,7 @@ module Recaptcha
|
|
163
161
|
|
164
162
|
def self.api_verification_enterprise(query_params, body, project_id, timeout: nil)
|
165
163
|
query = URI.encode_www_form(query_params)
|
166
|
-
uri = URI.parse(configuration.verify_url
|
164
|
+
uri = URI.parse("#{configuration.verify_url}/#{project_id}/assessments?#{query}")
|
167
165
|
http_instance = http_client_for(uri: uri, timeout: timeout)
|
168
166
|
request = Net::HTTP::Post.new(uri.request_uri)
|
169
167
|
request['Content-Type'] = 'application/json; charset=utf-8'
|
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.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason L Perry
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-08-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -161,7 +161,7 @@ licenses:
|
|
161
161
|
- MIT
|
162
162
|
metadata:
|
163
163
|
source_code_uri: https://github.com/ambethia/recaptcha
|
164
|
-
post_install_message:
|
164
|
+
post_install_message:
|
165
165
|
rdoc_options: []
|
166
166
|
require_paths:
|
167
167
|
- lib
|
@@ -169,15 +169,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
169
|
requirements:
|
170
170
|
- - ">="
|
171
171
|
- !ruby/object:Gem::Version
|
172
|
-
version: 2.
|
172
|
+
version: 2.7.0
|
173
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
174
174
|
requirements:
|
175
175
|
- - ">="
|
176
176
|
- !ruby/object:Gem::Version
|
177
177
|
version: '0'
|
178
178
|
requirements: []
|
179
|
-
rubygems_version: 3.
|
180
|
-
signing_key:
|
179
|
+
rubygems_version: 3.3.3
|
180
|
+
signing_key:
|
181
181
|
specification_version: 4
|
182
182
|
summary: Helpers for the reCAPTCHA API
|
183
183
|
test_files: []
|