Korzen
Bot Protection
In these docs

Protecting a checkout

Payment, login and sign-up routes: require the tag's token with any Korzen SDK or a Cloudflare Worker, start in monitor mode, and know who it stops.

Card testing is a script that tries stolen cards with small payments, one after another, to find which still work. The script usually never loads your page. The tag never runs, so the decision has no signal from a browser, and its class is unknown, which is allowed. A missing signal is never evidence of a bot, so Bot Protection does not call it one. On the actions such a script goes after, ask for proof of a real visit instead: the tag's token.

What protectedAction does

With "protected_action": true in the call (the SDKs' protectedAction option: protected_action in Python and Rust, ProtectedAction in Go and .NET), the action goes on only with a valid token the tag earned in that browser. Without one, the answer has token_required true. In block mode action is then block; in monitor mode action stays allow. The class does not change. The form's post spends the token, once per session and path an hour; up to three tries within two minutes are the same attempt, so a declined card and a second card still go through. A page load (GET, HEAD) spends no token, and the SDKs send the option with actions only. The rules in full: an action that needs the tag.

Put the tag on the page each action starts from: the checkout page, the login page, the sign-up page. The tag

Which routes

  • Payment: the post that charges the card or places the order, and any that adds a card or redeems a gift card. Card testing.
  • Login: the post that checks the password. Credential stuffing.
  • Sign-up: the post that creates the account. Fake accounts.

Leave it off the routes no page of yours leads to: your payment provider's webhooks, your mobile app's API, a partner's server. No tag runs there, so block mode would block every request.

In your code

Each tab shows where its framework's guide asks for it: the option of Korzen's package for the language, and in Ruby, which has none, the field in the call's body.

Node

// Express, with @korzen/bot-protection as the Express guide sets it up
const guard = protect({ client: korzen, ip: (_get, req) => req.ip, protectedAction: true });

app.get("/checkout", guard, showCheckout); // the page: a page load spends no token
app.post("/checkout", guard, placeOrder); // the action: it needs the tag's token

// Next.js, Hono or any handler of a Web Request
export const POST = withKorzen(placeOrder, { client, ip: ipFrom.vercel, protectedAction: true });

Go

mux.Handle("POST /checkout", bot.Protect(http.HandlerFunc(placeOrder), botprotection.Options{
	IP:           botprotection.RemoteIP,
	ProtectedAction: true, // the action needs the tag's token
}))

Python

# Flask, as the Django and Flask guide sets it up; FastAPI's KorzenASGI takes the same option
app.wsgi_app = KorzenWSGI(app.wsgi_app, client=korzen, prefixes=["/checkout"], ip=last_forwarded_ip,
                          protected_action=True)  # the action needs the tag's token; a page load spends none

PHP

// Protect, as the PHP, Symfony and Laravel guides set it up; the PSR-15 Middleware takes the same option
new Protect($korzen, ip: Ip::lastForwarded(...), protectedAction: true); // the action needs the tag's token

Java

// KorzenFilter, as the Spring Boot guide sets it up
KorzenFilter filter = KorzenFilter.builder(client)
    .ip(IpReader.LAST_FORWARDED)
    .protectedAction(true) // the action needs the tag's token; a page load spends none
    .build();

.NET

// As the ASP.NET Core guide sets it up
app.UseWhen(c => c.Request.Path.StartsWithSegments("/checkout"), branch =>
    branch.UseKorzenBotProtection(o =>
    {
        o.Ip = VisitorIp.LastForwarded;
        o.ProtectedAction = true; // the action needs the tag's token; a page load spends none
    }));

Ruby

# decide of the Rails guide sends it in the body.
path: path,
method: "POST",
protected_action: true # on payment, login and sign-up

Rust

// The layer, as the Rust guide sets it up
.layer(korzen.layer(Options::new().ip(Ip::Peer).protected_action(true))) // the action needs the tag's token

Cloudflare Worker

# wrangler.toml: the paths whose actions need the tag's token, by commas;
# one ending in * is a prefix.
[vars]
KORZEN_PROTECTED_ACTIONS = "/checkout,/login,/signup"

When the same function asks for every action, give it the choice: pass true from the payment, login and sign-up handlers and false from the rest. A misspelt field, such as protectedAction in the body, is refused with 400 and lets the visitor through, as every error does: check the first answers.

Monitor mode first

Turn it on while the account is in monitor mode. Every answer's action stays allow, so nobody is stopped; an action that came without a token answers token_required true. Watch two numbers for a few days:

  • the decisions on these routes with token_required true, in the answers your server logs;
  • the share Without a token in the integration health on the Set-up page. A high share there usually means a page that leads to the action has no tag, or a form sent before the tag has run: fix those first.

What is left is mostly scripts, and some people whose browser does not run the tag (below). Turn on block mode when that share is one you accept. Monitor and block mode

The actions for each class

The defaults suit a checkout. The class's action and the token are separate: with a valid token, the action is the class's; without one, in block mode it is block.

ClassActionOn a checkout
humanallowgo on
unknownallowgo on: with a token required, block mode refuses a script that skipped your page
botblockrefuse with the message a declined card shows, so the script learns nothing

Who it stops

A visitor whose browser does not run the tag holds no token: an ad blocker or a privacy extension that blocks it, a DNS filter that blocks Bot Protection's API host, JavaScript turned off. On a route with protected_action, in block mode, that visitor is refused on the action. That person cannot pay unless you give them another way.

  • Send it on the routes where a script costs you more than a stopped person: payment, login, sign-up. Never on every route.
  • Read the share in monitor mode before you turn on block mode, as above.
  • In onBlock, offer a way on that needs no tag of ours, if you have one: 3-D Secure, an email or phone code, a support contact.
  • Turn on first-party mode: the tag and its beacon then come from your own domain, so a DNS filter or a network that blocks Korzen's host no longer stops them.

When Bot Protection is slow or down, your server lets the visitor through, token or not: the call fails open.

protected_action raises the cost of taking an action without a real visit: the visitor's browser must run our tag on your page and earn a token, spent once. It is not a CAPTCHA and not a proof of a person: a well-funded bot that imitates a browser can still earn tokens, slowly and at a cost, and our classification judges those sessions as any other.