Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Rage Against The Malicious - The Battle of Spam...

Rage Against The Malicious - The Battle of Spam bots

A few years ago, my Rails application got thousands of signups instead of a few in a single night. Someone was flooding the registration form and asking for a ransom. It was painful for our email reputation since a confirmation email was sent for each signup. From that day on, I had the RAGE AGAINST THE MALICIOUS, and I decided to get rid of them once and for all. So, I started THE BATTLE OF SPAM BOTS.

I believe that a Turing test is a cat and mouse game, since when a new check is added it's just a matter of time before an attacker finds a workaround. Moreover, CAPTCHA solvers as a service cost a few bucks to solve a thousand. ⁠ They are solved by real humans… So I think that guessing if a client is a bot or a human is hopeless and we should change our strategy.

My ideal protection would be:

1. Zero human interactions, because humans are not the problem.
2. It must have a cost, or require something in finite quantity.
3. Decentralized, to not depend on a third-party service.

Fortunately, Hashcash was created in 1997 by Adam Back. It's a proof-of-work algorithm where it's extremely slow to create one (O(2^n)) and extremely fast to verify it (O(1)), since it requires only a single SHA-1 computation.

What if forms were protected by Hashcash? That's what I did, and it worked well. So I decided to extract it into a gem called ActiveHashcash, where you can protect your Rails application in four lines of code with zero third-party dependencies.

The goal of ActiveHashcash is not to block all bots. It's to ensure that your Rails application is a difficult target. So attackers must pay to rent a botnet and spend a lot of CPU time. Thus they will give up and move to an easier target.

Lightning talk given at Helvetic Ruby 2026.

Alexis Bernard

November 20, 2026

Transcript

23 slides
  1. # app/controllers/session_controller.rb class SessionController < ApplicationController include ActiveHashcash before_action :check_hashcash,

    only: :create end # app/views/session/new.html.erb <%= javascript_include_tag "hashcash", "data-turbo-track": "reload", defer: true %> <form> <%= hashcash_hidden_field_tag %> </form>
  2. # app/controllers/session_controller.rb class SessionController < ApplicationController include ActiveHashcash before_action :check_hashcash,

    only: :create end # app/views/session/new.html.erb <%= javascript_include_tag "hashcash", "data-turbo-track": "reload", defer: true %> <form> <%= hashcash_hidden_field_tag %> </form>
  3. # app/controllers/session_controller.rb class SessionController < ApplicationController include ActiveHashcash before_action :check_hashcash,

    only: :create end # app/views/session/new.html.erb <%= javascript_include_tag "hashcash", "data-turbo-track": "reload", defer: true %> <form> <%= hashcash_hidden_field_tag %> </form>
  4. # app/controllers/session_controller.rb class SessionController < ApplicationController include ActiveHashcash before_action :check_hashcash,

    only: :create end # app/views/session/new.html.erb <%= javascript_include_tag "hashcash", "data-turbo-track": "reload", defer: true %> <form> <%= hashcash_hidden_field_tag %> </form>

More Decks by Alexis Bernard

Other Decks in Programming