Behavior Rate

Detects bots that send too many requests in a short time window by tracking per-visitor request frequency.

The behavior rate checker tracks how many requests a visitor makes within a configurable sliding time window. Bots typically send requests much faster than humans. A scanner probing an entire site, a credential-stuffing script cycling through login combinations, or a price-scraper crawling product pages will all exceed a normal human browsing rate within seconds.

This checker runs in the heavy phase. It reads and writes to the cache layer configured in storage.


How It Works

The checker stores a request counter and a window start timestamp for each canary cookie in the cache. On every request:

  1. If no cache entry exists, the checker initializes a new entry and records the first request.
  2. If an entry exists and the current time is still within the window, the counter increments.
  3. When the counter exceeds behavioral_threshold, the checker applies the penalty and attaches BEHAVIOR_TOO_FAST.
  4. When the window expires (elapsed time exceeds behavioral_window), the counter resets and the window restarts.

The canary cookie links requests from the same browser session across multiple requests. Without a cookie (first-time visitors or bots that discard cookies), rate tracking does not apply.


Configuration

server.ts
await defineConfiguration({
  store: { main: { driver: 'sqlite', name: './bot-detector.db' } },
  checkers: {
    enableBehaviorRateCheck: {
      enable: true,
      behavioral_window: 60_000,   // 1 minute in milliseconds
      behavioral_threshold: 30,    // max requests per window
      penalties: 60,
    },
  },
})
enable
boolean
Enables or disables this checker. Default: true.
behavioral_window
number
Length of the sliding rate window in milliseconds. Default: 60000 (1 minute).
behavioral_threshold
number
Maximum number of requests allowed within behavioral_window before the penalty fires. Default: 30.
penalties
number
Score applied when the request count exceeds the threshold within the window. Default: 60.

Reason Codes

CodeTrigger
BEHAVIOR_TOO_FASTThe visitor exceeded behavioral_threshold requests within behavioral_window.

The default configuration allows 30 requests per minute. Adjust behavioral_threshold based on your application's expected usage patterns. A news site with long articles may see fewer than 5 page views per minute per user. A single-page application with many API calls may legitimately exceed 30 requests per minute.
This checker requires the canary cookie to be present. First-time visitors on their very first request have no cookie yet and are not evaluated by this checker. The cookie is set by detectBots() and is available starting from the second request.
Logo