The decision
What Zarex returns for each request, and how to read it in your code.
For each request, the SDK gets a decision. You receive it in onDeny and onDegraded, in req.zarex (Express, Fastify), in locals.zarex (SvelteKit), or as the return value of protect.
Fields
| Field | Type | Meaning |
|---|---|---|
allowed | boolean | true: the request goes through. If Zarex could not decide: true, except on a critical route (false). |
denied | boolean | true: a LIVE rule denied the request, or Zarex could not decide on a critical route (failedClosed). |
verdict | "ALLOW" · "DENY" | The verdict. When Zarex could not decide, it is "ALLOW" and degraded is true. |
degraded | boolean | true: Zarex could not decide (unavailable, too slow, IP address not found…). The request was let through, except on a critical route. |
failedClosed | boolean | true: denied because Zarex could not decide on a critical route (failMode: "closed"). Default response: 503. Since 0.2.0. |
id | string | The decision's identifier (32 hexadecimal characters), to find in the dashboard's decision log. Empty ("") if Zarex did not answer. |
results | RuleOutcome[] | The result of each rule. |
deniedBy | RuleOutcome | The first rule that denied the request (excluding DRY_RUN). |
retryAfterSeconds | number | For a rate limit: seconds to wait before retrying. |
ip | string | The visitor's IP address used for the decision. |
ipInfo | { country, asn } | Country (ISO code, "ZZ" if unknown) and network ("AS15169", "AS0" if unknown) of that address. |
rulesetVersion | string | Version of Zarex's rules that decided. Useful to compare a decision before and after an update. |
error | { code, message } | The reason, when the decision is degraded. |
A rule's result
Each element of results (and deniedBy) contains:
| Field | Meaning |
|---|---|
ruleType | The rule type: SHIELD, RATE_LIMIT, TOKEN_BUCKET, BOT_DETECTION, REQUEST_FILTER, SENSITIVE_INFO, EMAIL_VALIDATION, PHONE_VALIDATION or PROMPT_INJECTION. |
verdict | This rule's verdict: "ALLOW", "DENY", or "ERROR" if the rule could not be evaluated (for example an impossible DNS check); a rule in ERROR never blocks. |
dryRun | true if the rule is in DRY_RUN: its verdict blocked nothing. |
reason | The detail, specific to each rule type. |
Example: adapt the message to the rule
onDeny: (req, res, decision) => {
switch (decision.deniedBy?.ruleType) {
case "RATE_LIMIT":
return res.status(429).json({ error: "Too many attempts, try again later." });
case "EMAIL_VALIDATION":
return res.status(400).json({ error: "This email address cannot be used." });
default:
return res.status(403).json({ error: "Request denied." });
}
},Do not show the detail to the visitor
reason is for you, in your logs or the dashboard. For the visitor, a generic message is enough: there is no point telling an attacker which rule stopped them.