HttpProtectOptions interface
Configuration for the HttpProtect constructor.
Signature:
export interface HttpProtectOptions
Remarks
Every option has a working default, so new HttpProtect() is valid — but it connects to localhost:6379 and rate-limits on proxy-supplied headers, which is rarely what a deployed service wants.
HttpProtectOptions.ttl, HttpProtectOptions.maxRequests and HttpProtectOptions.banLimit can each also come from an environment variable, and an option passed here wins over its variable.
Properties
|
Property |
Modifiers |
Type |
Description |
|---|---|---|---|
|
number |
(Optional) Requests an address may accumulate before it is banned outright. | ||
|
(req: Request) => string | null |
(Optional) Resolver used to extract the client IP address from an incoming request. By default request-ip's getClientIp() is used, which reads the usual proxy headers (x-forwarded-for, x-real-ip, etc.). Because bans and rate limits are keyed by this address, blindly trusting forwarded headers lets a client spoof its IP. Override this with a trust-aware resolver (for example one built on top of the Spoofing cuts both ways here, and the second direction is the worse one. A client that varies the header evades its own counter; a client that forges someone else's address spends that address's budget and can get it banned — permanently, per HttpProtectOptions.banLimit. So on an untrusted path this option is the difference between a rate limiter and a way to have arbitrary third parties blocked. | ||
|
number |
(Optional) Requests an address may accumulate before it is answered 429. | ||
|
Redis |
(Optional) An existing ioredis client to use instead of opening another connection. | ||
|
RedisOptions |
(Optional) ioredis connection options, used only when HttpProtectOptions.redis is not given. | ||
|
string |
(Optional) Prefix for every Redis key this module writes. | ||
|
string[] |
(Optional) CIDR networks exempt from counting, limiting and banning. | ||
|
number |
(Optional) Seconds of silence from an address before its request counter is forgotten. |
Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.