This guide is for Express 4 and 5 on Node 22 or later. Node's fetch closes a connection after 4 seconds idle, so a server that asks less often opens a new TLS connection for most calls; an undici Agent with a longer keepAliveTimeout, passed as dispatcher, keeps it open.
Run Node 22.23.4, 24.22.1 or 26.12.1, or a later release of the same line. Earlier releases carry CVE-2026-111497, a flaw in the Brotli decoder that fetch and node:zlib use: malformed compressed data can corrupt the process's memory. Node 20, 23 and 25 get no fix.
Payment, login and sign-up routes: turn on protectedAction ("protected_action": true in the call), so a script that never loads your page cannot take the action. Protecting a checkout
The tag
Put the tag in the <head> of the layout that renders your sign-up, sign-in and checkout pages:
<script src="https://eu.korzen.dev/v1/tag.js" data-site-key="YOUR_SITE_KEY" async></script>
In the page, before the form is sent, call await window.korzen?.ready(): it reports what the visitor did since the tag last reported, and resolves within a few seconds whatever happens. The tag
For visitors whose network blocks Korzen's host, firstParty: true serves the tag and its beacon from your own domain. First-party mode
The call
Behind Cloudflare? A Worker can do this without changing your app. Cloudflare Workers
The client is the npm package @korzen/bot-protection, with no dependencies: it asks /v1/decide, gives up at your timeout and lets the visitor through on any error. Install it:
npm install @korzen/bot-protection
Then protect, as middleware on the route that creates the account. It keeps the answer on req.korzen, or null when there is none:
// app.js import express from "express"; import { Agent } from "undici"; // optional (npm install undici@7): keeps the connection open between calls import { createClient, protect } from "@korzen/bot-protection"; // The timeout for your server's region: https://korzen.dev/bot-protection/docs/server-call#latency const korzen = createClient({ apiKey: process.env.KORZEN_API_KEY, url: "https://eu.korzen.dev", timeoutMs: 200, dispatcher: new Agent({ keepAliveTimeout: 300_000 }) }); const app = express(); app.set("trust proxy", 1); // one proxy of yours in front: see "The visitor's IP" app.use(express.urlencoded({ extended: false })); const guard = protect({ client: korzen, ip: (_get, req) => req.ip, // with "trust proxy" set: see "The visitor's IP" protectedAction: true, // sign-up, login and payment: a script that never loaded your page holds no token; a page load spends none onBlock: (req, res) => res.status(403).send("We could not create your account."), }); app.get("/signup", guard, (req, res) => res.render("signup")); app.post("/signup", guard, async (req, res) => { const user = await createAccount(req.body); // your own code await saveRequestID(user.id, req.korzen?.request_id); // see "Apply the action" res.redirect("/welcome"); });
Measured against korzen.dev on 2026-10-18: Cloudflare sends no Keep-Alive hint, so on Node 18 to 26 fetch alone opened a new connection after 5 seconds idle, and with the Agent one connection served calls 120 seconds apart. Install undici 7: its Agent works with the fetch of Node 20 to 26. The fetch of Node 22 and 24 refuses the Agent of undici 8, which a plain npm install undici gives today (invalid onRequestStart method): the SDK then warns once and makes its calls without the Agent, so they still get answers, but the connection is not kept open.
To ask inside a handler instead, await korzen.decide(fromNodeRequest(req, { ip: (_get, r) => r.ip, path: "/signup" })) returns the answer, or null on any error. An answer whose action is not allow or block is an error too. To log why, give createClient an onAnswer: after each call it gets the status, Korzen-Request-Id, the RateLimit headers and, on an error, the problem's code.
The visitor's IP
req.ip is the connection's address unless you tell Express how many proxies are in front. Set trust proxy to that number (1 for one load balancer or nginx): Express then takes the address that proxy added to X-Forwarded-For, and ignores what the visitor wrote before it. true trusts the leftmost entry, which a visitor can write. Behind Cloudflare, pass ip: ipFrom.cloudflare to protect instead, if your server only takes traffic from Cloudflare.
Apply the action
Read only action. On block, answer with the same error the action shows when it fails for any other reason, so a bot learns nothing. The account starts in monitor mode, where action is always allow: nothing changes for visitors until you turn on block mode.
Keep the answer's request_id with what the action created, such as the account or the order: it names that decision when you ask us about it. The answer
Test it on your machine
Run your server with node --env-file=.env app.js and open it on localhost. Pages on localhost always accept the tag and are never listed as a domain. Locally the IP is 127.0.0.1 or ::1, and that is fine. In Docker on your machine, the app sees the bridge's address instead, such as 172.17.0.1, and that is fine too.
- Set
KORZEN_API_KEYin.envand open the sign-up page. In the browser's developer tools, the_kzcookie appears after a few seconds. - Sign up. The decision shows on the dashboard's Decisions page, under the path you sent.
- Check fail open: set a wrong key and sign up again. The call answers
401, and the sign-up goes through.
Common mistakes
app.set("trust proxy", true). It trusts every hop, soreq.ipbecomes what the visitor wrote inX-Forwarded-For.- No
trust proxyat all behind a load balancer. Every visitor then has the balancer's private IP, which Bot Protection takes for no IP: it sees much less, and the Set-up page warns you. - Calling
/v1/decidefrom the browser. The API key would reach every visitor; the call belongs on your server. - No timeout, or an error that stops the sign-up. Any answer other than
200, and no answer in time, means: let the visitor through. - A line in your log that starts
korzen: the visitor's IP sent to Bot Protection. The client writes it once, at the first decision whose IP is your own network's (a load balancer's, a proxy's, a container's), which Bot Protection judges as no IP: setipto the visitor's address (the visitor's IP). In Docker on your machine it is the bridge's address, and harmless there.