Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add spam protection to signup form #215

Merged
merged 2 commits into from
Jul 19, 2024
Merged

Conversation

chrislo
Copy link
Member

@chrislo chrislo commented Jul 19, 2024

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:

  1. I've disabled the gem-provided mock in favour of using Cloudflare's
    development/testing tokens so that we can see the real capture
    locally.
  2. Because we use turbo I've had to do ensure that the cloudflare
    script is always loaded and reloaded when the signup page is visited
    or re-rendered after a validation error. Setting data-turbo=false on
    the 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 and
    data-turbo-temporary options ensures that it is reloaded if the user
    navigates 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/

chrislo added 2 commits July 19, 2024 13:42
I'd like to use this in a subsequent commit to mock a call to
Cloudflare's turnstile API.

When I added this gem some of the existing feature specs started to
fail with an error message from Webmock like:

    Unregistered request: GET http://127.0.0.1:51768/__identify__

Apparently[1] this request comes from Capybara when it is running
feature specs with JS enabled, so I've configured Webmock to allow
connections to localhost.

[1] https://stackoverflow.com/questions/44999698/what-is-the-identify-route-that-capybara-looks-for
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:

1. I've disabled the gem-provided mock in favour of using Cloudflare's
development/testing tokens so that we can see the real capture
locally.
2. Because we use turbo I've had to do ensure that the cloudflare
script is always loaded and reloaded when the signup page is visited
or re-rendered after a validation error. Setting `data-turbo=false` on
the 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` and
`data-turbo-temporary` options ensures that it is reloaded if the user
navigates 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/
@chrislo chrislo merged commit 009ce06 into main Jul 19, 2024
2 checks passed
@chrislo chrislo deleted the add-spam-protection-to-signup-form branch July 19, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant