Skip to Content
ZarexDocs

SDK options

All the options shared by the Zarex SDKs, whatever your framework.

These options are passed to your framework's function: withZarex / zarexNext, zarex, zarexFastify, zarexHandle or zarexBun.

Options

OptionTypeRole
keystringRequired. The project's API key. It is never written to the logs.
rulesRule[]Required. From 1 to 10 rules.
ipSourcesee The IP addressHow to find the visitor's IP address.
inspectBodybooleanSend request bodies (Shield, sensitive data). Default true since 0.2.0 (false before); false to turn it off. It is inspected in memory, never stored.
inspectCookiesbooleanSend the Cookie header (Shield, cookie filters). Default false.
extraHeadersstring[]Additional headers to send. Authorization, Proxy-Authorization, Set-Cookie and X-Zarex-Key are never sent; Cookie only with inspectCookies.
call(request) => ProtectCallData to provide for each request: see below.
onDenyfunctionReplaces the denial response with yours. With Next.js, SvelteKit and Bun, it must return a Response (otherwise: default denial, the request stays blocked).
onDegradedfunctionCalled when Zarex could not decide (the request was let through, or denied on a critical route).
failMode"open" · "closed" · functionWhat to do if Zarex cannot decide: let through ("open", default) or deny ("closed"). See Critical routes. Since 0.2.0.
secureHeadersboolean or objectAdds HTTP security headers to your responses.
responseGuardboolean or objectMasks sensitive data that would end up in your responses.
timeoutMsnumberHow long to wait for the decision; beyond that, the request goes through. The default suits most cases.
breakerobject or falseAfter several consecutive failures, lets requests through without waiting during a short pause. false to disable it.
logger{ warn, error } or falseWhere to write the SDK's warnings. false to silence them.
baseUrlstringAddress of the Zarex service. Not needed in production; used for tests and local development (the ZAREX_URL variable does the same).

The data of call

call receives your framework's request and returns, for that request:

FieldUsed by
characteristicsRate limiting and token budget: the visitor's identifiers (for example { userId: "42" }), hashed before being sent. 16 at most: beyond that, the extra ones are ignored and the SDK writes it to your logs.
tokensRequestedToken budget: tokens consumed by the request. Default 1.
emailEmail validation.
phonePhone validation.
textSensitive data and prompt injection.
rulesReplaces the configured rules, for this request only.
failMode"open" or "closed" for this request only; takes precedence over the middleware option. See Critical routes.

call is a synchronous function: it returns its data directly, not a promise. So read values that are already available (body already parsed, user already loaded). An error in call is ignored: the request continues, without that data.

Direct use

For full control, or outside the supported frameworks, create an instance and call protect yourself:

import { createZarex, shield, rateLimit } from "@zarex/express"; // every package exports it

const zarex = createZarex({
  key: process.env.ZAREX_KEY!,
  ipSource: "socket",
  rules: [shield(), rateLimit({ max: 100, window: "1m" })],
});

const decision = await zarex.protect(
  { method: "GET", path: "/api/products", headers: { "user-agent": "…" }, socketIp: "41.7.7.7" },
  { characteristics: { userId: "42" } }
);

if (decision.denied) {
  // deny the request
}

protect never throws: if something goes wrong, the decision is allowed and degraded.

On this page