Skip to content

Hazeloft Security rules: bots, rate limits, IPs

Every Hazeloft Security rule in detail, from Shield and Bot Detection to Rate Limiting and IP Rules, with what it rejects and which options it has.

Last updated:

Each capability below is turned on separately and tuned from the console, on your API key. How to mount them in code is at the end of the page.

Bot Detection

Classifies the request by its User-Agent header and rejects automated clients. The allow list exempts certain bots, for example googlebot.

The allow list, on its own, does not verify identity: any request sending User-Agent: Googlebot/2.1 passes. With verify: true, an allowed bot is trusted only if the request’s IP address falls inside the ranges officially published by its operator (Google, Microsoft). A fake Googlebot is rejected with spoofed_bot. The ranges arrive through remote configuration; no DNS lookup is made per request.

Do not mount it on an API called by other servers: curl, HTTP libraries and integrators’ scripts look exactly like a bot.

Email validation

Checks the address in props.email: its length (254 characters in total, 64 before the @), its syntax, a built-in list of about 450 disposable domains and, optionally, free providers.

Option What it does
blockDisposable Rejects disposable email domains.
blockFree Rejects free providers. For most consumer products, that means rejecting most sign-ups.

The rule runs no MX or DNS lookup; that belongs to verifyDomain, in Sign-up protection. On top of the verdict, it returns the canonical form of the address (Gmail dots and + aliases removed), which is the right key for uniqueness and for limits.

Shield

Looks for attack signatures (SQL injection, XSS, path traversal, command and template injection) in the path, the query string, the user agent and, with scanBody on (the default), the request body.

Three things about body scanning:

  1. Values under sensitive-looking keys (password, token, secret, apikey, authorization, credential and their variants) are not scanned. Otherwise, strong passwords would produce rejections at sign-up.
  2. A body that looks like JSON but cannot be parsed is not scanned at all. The usual cause is truncation: scanning has a default ceiling of 64 KB.
  3. Everything else is scanned as raw text.

Body scanning catches automated scanners and sprayed payloads. It is not a security boundary, and Shield does not replace a WAF.

On routes that carry free text (editor, chat, import), the signatures produce more noise than signal. Turn body scanning off there:

rules: (config) => consoleRules(config, { scanBody: false }),

Sensitive Data

Rejects requests whose body contains card numbers (validated with Luhn), email addresses or phone numbers. You choose the kinds with deny. It is off by default.

The result carries only the kind of data found (detail.entities), never the value: a card number does not reach your logs through this rule.

Rate Limiting

Limits how many requests a client can make in an interval. It is the only rule that leaves your process: the counters are shared across all your instances.

Field What it means
name The limit’s name, 1–64 characters from [a-zA-Z0-9_.-]. Each name has its own counter.
window The window: "30s", "1m", "1h", "1d" or milliseconds; between 1 second and 24 hours.
max How many requests are allowed in the window.

Limits can also be defined from the console, with no code changes: at most 10 per key.

name is optional and defaults to "default". Two limits without a name increment the same counter, so give each its own. When the limit is exceeded, decision.retryAfter gives the number of seconds to wait.

The counter is kept per fingerprint, which defaults to the IP address. On routes where the user is signed in, you can count per user:

await security.protect(request, { fingerprint: `user:${session.userId}` });

You can also add limits from code, next to the ones from the console:

rules: (config) => [
  ...consoleRules(config),
  rateLimit({ name: "upload", window: "1h", max: 1000 }),
],

IP Rules

Two lists: blocked addresses and trusted addresses. They accept single addresses or CIDR ranges, IPv4 and IPv6, at most 200 entries per list.

Trusted addresses skip the other checks, not just blocking. A wide range there means protection turned off for everything that comes in through it.

Challenge

Verifies the x-hz-challenge header: a token signed by your server plus a proof-of-work computation solved in the browser, redeemable once. From the console you tune the difficulty (13 bits by default, between 8 and 24) and the token’s validity (120 seconds by default, between 30 and 300).

A passed challenge proves that JavaScript ran and that a computation cost was paid. The full wiring is in Sign-up protection.

Mounting in code

consoleRules brings the capabilities above with the settings from the console:

import {
  HazeloftSecurity,
  consoleRules,
  createConfigClient,
  createEventReporter,
} from "@hazeloft/security";

export const security = new HazeloftSecurity({
  apiKey: process.env.HAZELOFT_SECURITY_API_KEY,
  configClient: createConfigClient(),
  eventReporter: createEventReporter(),
  rules: consoleRules,
});

The challenge needs two things the console cannot know: the secret the tokens are signed with and the place where you remember used nonces.

rules: (config) =>
  consoleRules(config, {
    challenge: {
      secret: process.env.HAZELOFT_CHALLENGE_SECRET,
      action: "sign-up",
      isFresh: consumeNonce, // marks the nonce as used; returns false the second time
    },
  }),

You can also list the rules by hand, without the console: shield(), detectBot(), validateEmail(), detectSensitiveInfo(), challenge() and rateLimit() are exported from @hazeloft/security and each accepts mode: "dry_run".

All documentationSecurity product page

This site uses measurement and advertising technologies. You can accept or decline them.

How we handle your data: Privacy policy · Cookie policy