Add spam protection to signup form #215
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the Postmark activity I've noticed a lot of "verify your email"
messages being sent and not actioned. Many of these are bouncing,
which hurts our email deliverability. Anecdotally more legitimate
emails from jam.coop are going to spam than before.
To mitigate this I've added a Cloudflare Turnstile[1] "captcha" to the
registration form to hopefully prevent these non-genuine
signups (which I assume are from scripts) from occuring.
I decided to use the rails-cloudflare-turnstile[2] gem to do the heavy
lifting here, primarily to avoid having to write the code that makes
the verfication request to the cloudflare API[3].
I've mostly followed the setup instructions for that gem with a couple
of changes:
development/testing tokens so that we can see the real capture
locally.
script is always loaded and reloaded when the signup page is visited
or re-rendered after a validation error. Setting
data-turbo=false
onthe signup form ensures that it is submitted without turbo and
therefore releads the cloudflare JS widget on re-render. Including the
cloudflare script with the
data-turbo-track
anddata-turbo-temporary
options ensures that it is reloaded if the usernavigates away from signup and back again.
I've also set the two new ENV variables using the credentials provided
by Cloudflare[4].
[1] https://developers.cloudflare.com/turnstile/
[2] https://github.com/instrumentl/rails-cloudflare-turnstile
[3] https://github.com/instrumentl/rails-cloudflare-turnstile/blob/main/lib/rails_cloudflare_turnstile/controller_helpers.rb
[4] https://dash.cloudflare.com/