recaptcha 5.12.2 → 5.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a8e985580ee7e6829b2b213403c7a7062167dac7f5184800b6585b0897cdaab
4
- data.tar.gz: 9b7dd59495998217cdc96ec7436163f3faec7fccdc5c60ebd21611ccec1f9ad5
3
+ metadata.gz: 413f379aca4968847b291687d0c36e7ef432f7d6ebdce5b87c164afe45291b83
4
+ data.tar.gz: e277f54b020495ffe3a431e51ff3d8ed6080d01bc7a93a291f60894e888bc102
5
5
  SHA512:
6
- metadata.gz: ce899e801c0679cfa3e4074826ef349d6142914fafbef12bfd69467811b3e7d4855638f53f13f469224f5500911f4481240c54d5f394bc767337a1a3f747b778
7
- data.tar.gz: d4c7626d90d7423d446bb03178476c30e78db7a3834443f70bb395f3fe8380b7e5ae70cb8ab5a2931e9f82e1a0b5053ac59f1dad8ac6244f55bc9138e089b86c
6
+ metadata.gz: bcf166047a4de7972b3040301fb51f7b8b0a17b5c7f46ba9cef127c3418538635ffe707ac208b091254da5501538134285870f01ff880555e21cc7ff2ab39bf8
7
+ data.tar.gz: 9e8ad8cd049c352a48810b19c1611ac82f62d196a91af17f2baa8f568e9a77bc0d7aac3662cd52174cccca371afceae076bdb6d4f17072be90cf51268d714100
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## Next
2
2
 
3
+ ## 5.13.0
4
+ * Added option to ignore_no_element.
5
+
6
+ ## 5.12.3
7
+ * Remove score fallback for enterprise
8
+ * Update enterprise tests to v1 assessment schema
9
+
3
10
  ## 5.12.2
4
11
  * Fix minimum score for enterprise
5
12
 
data/README.md CHANGED
@@ -427,6 +427,7 @@ but only accepts the following options:
427
427
  | `:inline_script` | If `true`, adds an inline script tag that calls `grecaptcha.execute` for the given `site_key` and `action` and calls the `callback` with the resulting response token. Pass `false` if you want to handle calling `grecaptcha.execute` yourself. (default: `true`) |
428
428
  | `:element` | The element to render, if any (default: `:input`)<br/>`:input`: Renders a hidden `<input type="hidden">` tag. The value of this will be set to the response token by the default `setInputWithRecaptchaResponseTokenFor{action}` callback.<br/>`false`: Doesn't render any tag. You'll have to add a custom callback that does something with the token. |
429
429
  | `:turbolinks` | If `true`, calls the js function which executes reCAPTCHA after all the dependencies have been loaded. This cannot be used with the js param `:onload`. This makes reCAPTCHAv3 usable with turbolinks. |
430
+ | `:ignore_no_element` | If `true`, adds null element checker for forms that can be removed from the page by javascript like modals with forms. (default: true) |
430
431
 
431
432
  [JavaScript resource (api.js) parameters](https://developers.google.com/recaptcha/docs/invisible#js_param):
432
433
 
@@ -16,6 +16,7 @@ module Recaptcha
16
16
  options[:render] = site_key
17
17
  options[:script_async] ||= false
18
18
  options[:script_defer] ||= false
19
+ options[:ignore_no_element] = options.key?(:ignore_no_element) ? options[:ignore_no_element] : true
19
20
  element = options.delete(:element)
20
21
  element = element == false ? false : :input
21
22
  if element == :input
@@ -138,6 +139,7 @@ module Recaptcha
138
139
  nonce = options.delete(:nonce)
139
140
  skip_script = (options.delete(:script) == false) || (options.delete(:external_script) == false)
140
141
  ui = options.delete(:ui)
142
+ options.delete(:ignore_no_element)
141
143
 
142
144
  data_attribute_keys = [:badge, :theme, :type, :callback, :expired_callback, :error_callback, :size]
143
145
  data_attribute_keys << :tabindex unless ui == :button
@@ -206,7 +208,7 @@ module Recaptcha
206
208
  })
207
209
  };
208
210
 
209
- #{recaptcha_v3_define_default_callback(callback) if recaptcha_v3_define_default_callback?(callback, action, options)}
211
+ #{recaptcha_v3_define_default_callback(callback, options) if recaptcha_v3_define_default_callback?(callback, action, options)}
210
212
  </script>
211
213
  HTML
212
214
  end
@@ -224,7 +226,7 @@ module Recaptcha
224
226
  });
225
227
  });
226
228
  };
227
- #{recaptcha_v3_define_default_callback(callback) if recaptcha_v3_define_default_callback?(callback, action, options)}
229
+ #{recaptcha_v3_define_default_callback(callback, options) if recaptcha_v3_define_default_callback?(callback, action, options)}
228
230
  </script>
229
231
  HTML
230
232
  end
@@ -235,12 +237,12 @@ module Recaptcha
235
237
  options[:inline_script] != false
236
238
  end
237
239
 
238
- private_class_method def self.recaptcha_v3_define_default_callback(callback)
240
+ private_class_method def self.recaptcha_v3_define_default_callback(callback, options)
239
241
  <<-HTML
240
- var #{callback} = function(id, token) {
241
- var element = document.getElementById(id);
242
- element.value = token;
243
- }
242
+ var #{callback} = function(id, token) {
243
+ var element = document.getElementById(id);
244
+ #{element_check_condition(options)} element.value = token;
245
+ }
244
246
  HTML
245
247
  end
246
248
 
@@ -328,5 +330,9 @@ module Recaptcha
328
330
  private_class_method def self.hash_to_query(hash)
329
331
  hash.delete_if { |_, val| val.nil? || val.empty? }.to_a.map { |pair| pair.join('=') }.join('&')
330
332
  end
333
+
334
+ private_class_method def self.element_check_condition(options)
335
+ options[:ignore_no_element] ? "if (element !== null)" : ""
336
+ end
331
337
  end
332
338
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Recaptcha
4
- VERSION = '5.12.2'
4
+ VERSION = '5.13.0'
5
5
  end
data/lib/recaptcha.rb CHANGED
@@ -77,7 +77,7 @@ module Recaptcha
77
77
  body['event']['userIpAddress'] = options[:remote_ip] if options.key?(:remote_ip)
78
78
 
79
79
  reply = api_verification_enterprise(query_params, body, project_id, timeout: options[:timeout])
80
- score = reply.dig('riskAnalysis', 'score') || reply['score']
80
+ score = reply.dig('riskAnalysis', 'score')
81
81
  token_properties = reply['tokenProperties']
82
82
  success = !token_properties.nil? &&
83
83
  token_properties['valid'].to_s == 'true' &&
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.12.2
4
+ version: 5.13.0
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: 2022-09-05 00:00:00.000000000 Z
11
+ date: 2023-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -163,7 +163,7 @@ licenses:
163
163
  - MIT
164
164
  metadata:
165
165
  source_code_uri: https://github.com/ambethia/recaptcha
166
- post_install_message:
166
+ post_install_message:
167
167
  rdoc_options: []
168
168
  require_paths:
169
169
  - lib
@@ -178,8 +178,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  requirements: []
181
- rubygems_version: 3.1.6
182
- signing_key:
181
+ rubygems_version: 3.3.3
182
+ signing_key:
183
183
  specification_version: 4
184
184
  summary: Helpers for the reCAPTCHA API
185
185
  test_files: []