devise-cloudflare-turnstile 0.10.0 → 0.11.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b29bbe949d442bee08751e705b15350414748639b11d73296b84647a3492325e
4
- data.tar.gz: 11159165db1ab0a0b9d1f3d09367c2ece59eff3d2fb875b1f84bd465be37c43e
3
+ metadata.gz: 95edf74912abe68de902d9a5e3cf58c59f8f44d3a60f0b5cfb3ac6105e981ff6
4
+ data.tar.gz: b01582121ba114a8044e010fcd782e8baca8100a220150c4eb6dc2f85af9ac7d
5
5
  SHA512:
6
- metadata.gz: 9323f0c853e494ff79d6c1a7e02e0918e1931072a147c3fbeec1424bdc4966fdaeb34ae75fb333b605f28b22238416c728ba24638467b27380a17ac93ac70e82
7
- data.tar.gz: ce5cf4f403126a3a8ac08fb8613ddeb300f21085aa0e47cf20a195cd78a3930fe0207ac12b530c4c0c53d936646247667a1cf5a9ccfaf70505824386fed4bc46
6
+ metadata.gz: dc8dba667dcec474d7464faa259cccc99abaa45823fcedfe26520098ede8b9fd4c78a0849cf0c0e03b85550e0f7cd2527a55c7d60628ba0f243f17aa7074e0ee
7
+ data.tar.gz: 05ccb44987629b192af3087fcbe463989b30791f31526c3f8c134dc49e45cf5d6e79b7d44dba4de5d948b3ddc23ba55fa6da1ef18a56cfbfdcab9113691860cf
data/README.md CHANGED
@@ -85,7 +85,9 @@ That's it — all Devise forms are now protected.
85
85
  ### How It Works
86
86
 
87
87
  * **Controller** — a `before_action` on every Devise controller verifies the Turnstile response on `create` and re-renders the form with an error if it fails.
88
- * **View** — on Devise form pages, the two layout helpers emit the site key and load the injector JavaScript, which adds a `cf-turnstile` widget before each submit button.
88
+ * **View** — on Devise form pages, the two layout helpers emit the site key and load the injector JavaScript, which adds a `cf-turnstile` widget before each submit button. Rails `button_to` action buttons (e.g. OAuth sign-in or log out) are skipped.
89
+
90
+ The widget appears only on the `create` forms (and their `new` pages) — sign in, sign up, password-reset request, and resend confirmation/unlock. Authenticated and edit pages such as account settings, password-reset completion, and accepting an invitation are left untouched.
89
91
 
90
92
  Widget rendering, script loading, CSP nonces, and Turbo/Turbolinks handling are delegated to [cloudflare-turnstile-rails](https://github.com/vkononov/cloudflare-turnstile-rails).
91
93
 
@@ -176,10 +178,11 @@ end
176
178
 
177
179
  | Situation | Behavior |
178
180
  |-----------|----------|
179
- | No custom controllers | All Devise controllers are protected automatically |
181
+ | No custom controllers | All Devise controllers are protected automatically on their `create` actions |
182
+ | Edit / authenticated pages (account settings, password-reset completion, accept invitation) | Not protected — the widget only appears on the `create` forms |
180
183
  | Custom controller with `skip_turnstile` (or config `skip`) | That controller/action opts out of both widget and verification |
181
184
  | No custom views | Devise's default views render; the widget still injects |
182
- | Custom view without a widget | The widget is still injected before the submit button |
185
+ | Custom view without a widget | The widget is injected before the submit button; Rails `button_to` action buttons are skipped |
183
186
  | Custom view with `cloudflare_turnstile_tag` | Your widget is used as-is; nothing is auto-injected |
184
187
  | Invisible vs visible widget | Determined by the site key's widget type in the Cloudflare dashboard |
185
188
 
@@ -74,7 +74,12 @@
74
74
  return;
75
75
  }
76
76
 
77
- forms = document.querySelectorAll('form[method="post"], form[method="POST"]');
77
+ /*
78
+ * Skip Rails button_to forms (rendered with class "button_to"), such as
79
+ * OAuth sign-in, log out, or delete buttons. They are action buttons, not
80
+ * user-input forms, so they should never get a Turnstile widget.
81
+ */
82
+ forms = document.querySelectorAll('form[method="post"]:not(.button_to), form[method="POST"]:not(.button_to)');
78
83
 
79
84
  for (i = 0; i < forms.length; i++) {
80
85
  form = forms[i];
@@ -10,7 +10,7 @@ module Devise
10
10
  class_attribute :_turnstile_skip_rules, instance_accessor: false
11
11
  self._turnstile_skip_rules = []
12
12
 
13
- before_action :verify_cloudflare_turnstile!, only: :create
13
+ before_action :verify_cloudflare_turnstile!, if: :turnstile_verify_action?
14
14
  before_action :set_turnstile_page_marker, if: :turnstile_form_action?
15
15
  end
16
16
 
@@ -85,13 +85,21 @@ module Devise
85
85
  @_devise_turnstile_protected = true
86
86
  end
87
87
 
88
- # Include create/update so failed submissions that re-render the form
89
- # still emit the Turnstile meta tag and scripts. Without this, Turbo
90
- # merges a head that omits them and the widget never comes back.
88
+ # Verify only on create. Kept as a predicate rather than `only: :create`
89
+ # so the callback is skipped cleanly on controllers without a create
90
+ # action instead of raising.
91
+ def turnstile_verify_action?
92
+ action_name == 'create'
93
+ end
94
+
95
+ # The widget shows on the create forms (`new`) and on `create` itself, so
96
+ # a failed submission that re-renders still emits the meta tag and scripts
97
+ # that Turbo needs. Edit/update pages are excluded because only `create`
98
+ # is verified.
91
99
  def turnstile_form_action?
92
100
  return false if turnstile_skipped?
93
101
 
94
- action_name.in?(%w[new edit create update])
102
+ action_name.in?(%w[new create])
95
103
  end
96
104
 
97
105
  def turnstile_skipped?
@@ -1,7 +1,7 @@
1
1
  module Devise
2
2
  module Cloudflare
3
3
  module Turnstile
4
- VERSION = '0.10.0'.freeze
4
+ VERSION = '0.11.0'.freeze
5
5
  end
6
6
  end
7
7
  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.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Kononov