Skip to content

Rate limit a login page

Limit how many sign-in attempts each client IP can make, first in log-only mode, then blocking.

Updated View as Markdown
  1. Add a rate limit rule to the WAF’s rules, in log-only mode. It counts each client IP’s POSTs to /login and records those over 20 in 5 minutes:

    {
      "name": "login",
      "action": "rateLimit",
      "mode": "log",
      "rateLimit": { "limit": 20, "windowSeconds": 300 },
      "conditions": [
        { "type": "equals", "negate": false, "target": "path", "value": "/login", "caseSensitive": false },
        { "type": "equals", "negate": false, "target": "method", "value": "POST", "caseSensitive": false }
      ]
    }

    Replace the WAF with UpdateWaf, sending the ETag you read in If-Match.

  2. With logging on, see which clients went over:

    ezgh obs search --environment production --service ezgh.waf --from 1d --contains '"terminatingRule":{"name":"login"'
  3. If only abusive clients show up, change the rule’s mode to block. Clients over the limit are answered 403 until their count in the last 5 minutes falls back under 20.

A client behind a shared address, such as an office’s network, shares its count with everyone there. Exempt such an address with an allow rule above the limit.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close