Critical routes
Deny a request when Zarex cannot decide, on your login or payment routes only (failMode, since 0.2.0).
By default, if Zarex cannot decide, the request goes through without inspection: your site stays online whatever happens (fail-open). That is the right choice for most pages.
On a critical route (login, password reset, Mobile Money payment…), an attacker who made Zarex unavailable for your site would get through with no rate limiting and no Shield. For these routes, failMode: "closed" denies the request when Zarex cannot decide. Available since version 0.2.0.
When Zarex cannot decide
| Cause | Code (decision.error.code) |
|---|---|
| Zarex does not answer in time | timeout |
| Connection impossible | network |
| Several failures in a row: calls paused | circuit_open |
| Service error | server_error, engine_error, bad_response |
| Account's technical ceiling reached | quota_exceeded |
| API key rejected | unauthorized, forbidden |
| Visitor's IP address not found | ip_unresolved |
On a closed route, all these causes deny the request, including a configuration error: a revoked key shows up immediately instead of silently letting traffic through.
Close a route
The simplest: only close sensitive routes.
// proxy.ts: a single function for the whole site, the route picks its mode
const guard = zarexNext({
key: process.env.ZAREX_KEY!,
rules: [shield(), rateLimit({ max: 10, window: "1m" })],
failMode: (request) =>
new URL(request.url).pathname.startsWith("/api/login") ? "closed" : "open",
});With protect() directly, pass the option on the call: zarex.protect(input, { failMode: "closed" }). A value given on the call takes precedence over the middleware's. An unknown value (a typo such as "close") is treated as "closed", and the SDK writes it to your logs. If your failMode function throws, the route is closed.
What the visitor receives
A 503 Service Unavailable response, with Retry-After: 30 and a generic body:
{ "error": { "code": "unavailable", "message": "Service temporarily unavailable", "request_id": "" } }Nothing reveals the cause, neither Zarex nor your quota. To show your own page, use onDeny: the decision then carries failedClosed: true, degraded: true, and the cause in error.code.
onDeny: (request, decision) =>
decision.failedClosed
? new Response("Service temporarily unavailable, please try again in a moment.", { status: 503 })
: new Response("Access denied", { status: 403 }),onDegraded is also called, for your logs and alerts.
What does not change
- A real decision is never replaced: a legitimate request goes through, an attack still receives
403(or429for a rate limit). - Open routes (the default) still let traffic through when Zarex cannot decide.
Only close sensitive routes
A closed route becomes unavailable when Zarex is. If you close your whole site, a Zarex outage makes it entirely unreachable.