# Rules (/docs/risk/rules)

The score weighs every signal together. When you know exactly what you want for a case, write a
rule. Rules are checked after your [lists](/docs/risk/lists-and-feedback#lists) and before the score
thresholds. The first enabled rule (lowest `position`, then oldest) whose conditions match the event
decides, and the assessment gets a `rule.matched` reason naming it.

```ts twoslash
import { Coss } from "coss";
const coss = new Coss();
// ---cut---
const { data: rule } = await coss.risk.rules.create({
  name: "Disposable email from a data center",
  position: 10,
  events: ["signup"],
  conditions: [
    { field: "email.disposable", operator: "is", value: true },
    { field: "ip.hosting", operator: "is", value: true },
  ],
  action: "block",
});

// Checked first (lower position): trust logins from your office network.
await coss.risk.rules.create({
  name: "Office network",
  position: 0,
  events: ["login"],
  conditions: [{ field: "ip.asn", operator: "in", value: ["64500", "64501"] }],
  action: "allow",
});
```

- `match: "all"` (the default) needs every condition; `match: "any"` needs one.
- `events` limits a rule to some events; empty means every event.
- A field without a value never matches, whatever the operator: a rule about `ip.country` doesn't
  fire for an assessment without an IP address, and `neq` doesn't fire either.
- Rules see the facts behind [disabled reasons](/docs/risk/settings#disabled-reasons), so you can
  turn a reason off for the score and still use it in a rule.
- An environment has at most 50 rules. Edit them in the dashboard (**Risk → Rules**) or with
  `coss.risk.rules.update(id, { enabled: false })`.

## Fields [#fields]

String comparisons ignore case; `in` and `not_in` take a list of up to 100 strings.

| Field | Type | Operators | Meaning |
| --- | --- | --- | --- |
| `email.valid` | boolean | is | Email is valid |
| `email.disposable` | boolean | is | Email is disposable |
| `email.undeliverable` | boolean | is | Email domain can't receive mail |
| `email.role_account` | boolean | is | Email is a role account |
| `email.free_provider` | boolean | is | Email is at a free provider |
| `email.typo` | boolean | is | Email domain looks like a typo |
| `email.domain_new` | boolean | is | Email domain is new |
| `email.domain` | string | eq, neq, in, not_in | Email domain |
| `email.domain_age_days` | number | eq, neq, gt, gte, lt, lte | Email domain age (days) |
| `ip.tor` | boolean | is | IP is a Tor exit |
| `ip.hosting` | boolean | is | IP is a cloud or hosting network |
| `ip.vpn` | boolean | is | IP is a VPN |
| `ip.proxy` | boolean | is | IP is a proxy |
| `ip.relay` | boolean | is | IP is a privacy relay |
| `ip.private` | boolean | is | IP is private |
| `ip.country` | string | eq, neq, in, not_in | IP country (ISO code) |
| `ip.asn` | string | eq, neq, in, not_in | IP network (AS number) |
| `ip.hosting_provider` | string | eq, neq, in, not_in | IP hosting provider |
| `captcha.passed` | boolean | is | Captcha passed |
| `duplicate.canonical_mailbox` | boolean | is | Mailbox already has an account |
| `duplicate.device` | boolean | is | Device already has an account |
| `history.fraud` | boolean | is | Seen in fraud before |
| `login.new_country` | boolean | is | Login from a new country |
| `login.new_network` | boolean | is | Login from a new network |
| `content.spam` | number | eq, neq, gt, gte, lt, lte | Content spam score (0-1) |
| `content.phishing` | number | eq, neq, gt, gte, lt, lte | Content phishing score (0-1) |
| `content.malware` | number | eq, neq, gt, gte, lt, lte | Content malware score (0-1) |
| `content.fraud` | number | eq, neq, gt, gte, lt, lte | Content fraud score (0-1) |
| `checkout.amount` | number | eq, neq, gt, gte, lt, lte | Checkout amount (minor units) |
| `checkout.currency` | string | eq, neq, in, not_in | Checkout currency (ISO code) |
| `checkout.card_country` | string | eq, neq, in, not_in | Card country (ISO code) |
| `checkout.card_funding` | string | eq, neq, in, not_in | Card funding (credit, debit, prepaid) |
| `checkout.billing_country` | string | eq, neq, in, not_in | Billing country (ISO code) |
| `checkout.shipping_country` | string | eq, neq, in, not_in | Shipping country (ISO code) |
| `device.automation` | boolean | is | Browser is automated |
| `device.timezone` | string | eq, neq, in, not_in | Browser time zone (IANA) |
| `device.language` | string | eq, neq, in, not_in | Browser language |
| `score` | number | eq, neq, gt, gte, lt, lte | Score (0-1) |
| `velocity.ip_1h` | number | eq, neq, gt, gte, lt, lte | Events from the IP (1 h) |
| `velocity.ip_24h` | number | eq, neq, gt, gte, lt, lte | Events from the IP (24 h) |
| `velocity.subnet_1h` | number | eq, neq, gt, gte, lt, lte | Events from the subnet (1 h) |
| `velocity.subnet_24h` | number | eq, neq, gt, gte, lt, lte | Events from the subnet (24 h) |
| `velocity.email_domain_1h` | number | eq, neq, gt, gte, lt, lte | Events with the email domain (1 h) |
| `velocity.email_domain_24h` | number | eq, neq, gt, gte, lt, lte | Events with the email domain (24 h) |
| `velocity.mailbox_1h` | number | eq, neq, gt, gte, lt, lte | Events with the mailbox (1 h) |
| `velocity.mailbox_24h` | number | eq, neq, gt, gte, lt, lte | Events with the mailbox (24 h) |
| `velocity.user_1h` | number | eq, neq, gt, gte, lt, lte | Events of the user (1 h) |
| `velocity.user_24h` | number | eq, neq, gt, gte, lt, lte | Events of the user (24 h) |
| `velocity.card_1h` | number | eq, neq, gt, gte, lt, lte | Events with the card (1 h) |
| `velocity.card_24h` | number | eq, neq, gt, gte, lt, lte | Events with the card (24 h) |
| `velocity.device_1h` | number | eq, neq, gt, gte, lt, lte | Events from the device (1 h) |
| `velocity.device_24h` | number | eq, neq, gt, gte, lt, lte | Events from the device (24 h) |
