What it is
A firewall service for a group of products, behind Cloudflare. Before a product does anything worth abusing, like sending a one-time password, its backend asks the firewall first. The firewall checks the visitor's captcha, applies layered rate limits, logs the decision and answers allow or block, with a reason the product can show.
The problem
Anything that sends a one-time password costs money every time it runs, and it's the first thing bots find. Each product could add its own captcha and its own counters, and each would get the details slightly wrong in its own way. One service doing it for all of them means one place to get it right, and one log to read when something looks odd.
What I built
- A firewall service in Laravel on Octane, with Redis behind it
- Browser sessions that start with an invisible reCAPTCHA v3 check and last ten minutes
- Layered rate limits for each product and action: per person, per IP, per repeated payload, and per number of different targets one IP tries
- Server-side checks for reCAPTCHA v3 and Cloudflare Turnstile, managed and invisible, with every token tied to the action it was issued for
- A log of every decision, with a dashboard to filter it by product, action, IP and outcome
The interesting parts
One limit is really four
Sending a one-time password isn't one limit. It's four windows stacked on top of each other: one every two seconds, three a minute, ten an hour and thirty a day for the same person, and a separate set for how many different numbers one IP can send to. Only the daily window emails a human. The others just say no.
Rejected attempts are free
The firewall checks every limit before it counts anything, and a request is only counted once it's allowed through. Someone hammering a blocked form isn't pushed deeper into the block for it. The windows run out on schedule, whatever they do in the meantime.
Tokens tied to actions
A captcha token proves someone solved a challenge, not what they solved it for. The server checks that each token's action matches the endpoint it's used on, holds reCAPTCHA v3 to a score of 0.5, and sends Turnstile an idempotency key, so retrying a check after a network blip doesn't burn the token.