Skip to Content
ZarexDocs

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

FieldTypeMeaning
allowedbooleantrue: the request goes through. If Zarex could not decide: true, except on a critical route (false).
deniedbooleantrue: 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.
degradedbooleantrue: Zarex could not decide (unavailable, too slow, IP address not found…). The request was let through, except on a critical route.
failedClosedbooleantrue: denied because Zarex could not decide on a critical route (failMode: "closed"). Default response: 503. Since 0.2.0.
idstringThe decision's identifier (32 hexadecimal characters), to find in the dashboard's decision log. Empty ("") if Zarex did not answer.
resultsRuleOutcome[]The result of each rule.
deniedByRuleOutcomeThe first rule that denied the request (excluding DRY_RUN).
retryAfterSecondsnumberFor a rate limit: seconds to wait before retrying.
ipstringThe 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.
rulesetVersionstringVersion 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:

FieldMeaning
ruleTypeThe rule type: SHIELD, RATE_LIMIT, TOKEN_BUCKET, BOT_DETECTION, REQUEST_FILTER, SENSITIVE_INFO, EMAIL_VALIDATION, PHONE_VALIDATION or PROMPT_INJECTION.
verdictThis 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.
dryRuntrue if the rule is in DRY_RUN: its verdict blocked nothing.
reasonThe 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.

On this page