Limit Request Rate
Request rate limiting uses the leaky bucket algorithm to control the request processing rate.
A CC (Challenge Collapsar) attack continuously sends large numbers of HTTP or HTTPS requests to consume application connections, computing resources, or upstream service capacity, causing legitimate requests to slow down or fail. Unlike volumetric attacks that primarily consume network bandwidth, CC attacks often target resource-intensive endpoints such as login, search, and dynamic query APIs. Each request can appear legitimate, so effective protection needs to consider both request characteristics and access frequency.
OpenResty Edge provides multiple layers of protection, from request controls to network-layer IP blocking. Page rules define where a policy applies, group requests by keys such as client IP address, URI, and Cookie, and delay, challenge, reject, or block abnormal traffic when a threshold is reached.
Request-layer actions protect HTTP and HTTPS endpoints and are the primary controls for mitigating CC attacks.
Network-layer actions drop packets from the source IP at the operating system level and therefore have a broader impact than rejecting an individual HTTP request. Verify that the source IP is reliable before using these actions to avoid blocking legitimate users behind a shared egress, proxy, or NAT gateway.
The following capabilities do not identify typical HTTP CC requests, but they can protect TLS handshake resources or control response bandwidth.
| Action | Controlled object | Trigger | Handling | Typical use case |
|---|---|---|---|---|
| Limit request rate | HTTP/HTTPS requests | Request rate reaches the delay or rejection threshold | Delay or execute a rejection action | Smooth traffic bursts and protect high-frequency endpoints |
| Limit request count | HTTP/HTTPS requests | Request count exceeds the threshold in a fixed time window | Execute a rejection action | Limit login, CAPTCHA, or API attempts |
| Delay requests | Requests matching a page rule | A request satisfies the rule conditions | Continue processing after a fixed delay | Reduce the efficiency of automated attempts and low-rate attacks |
| Block requests | HTTP/HTTPS requests | The request rate reaches the threshold in consecutive time windows | Block for a configured period | Handle clients that sustain a high request rate |
| Block source IP | All packets from a source IP | A request satisfies the rule conditions | Drop packets at the operating system level | Quickly isolate a confirmed attack source |
| Block an IP list | Source IPs in a list | The source IP matches a predefined list | Drop packets at the operating system level | Apply a blacklist or threat intelligence feed |
| Limit SSL handshake rate | TLS handshakes | The handshake rate for a client IP reaches the threshold | Delay or reject | Mitigate abnormal TLS handshake consumption |
| Limit response data rate | HTTP/HTTPS responses | A request satisfies the rule conditions | Limit the response transmission rate | Control bandwidth used by downloads or large responses |
Page rule conditions determine which requests enter a protection policy. Start with resource-intensive or automation-prone endpoints such as login, search, checkout, and dynamic APIs instead of applying the same threshold to the entire application.
Keys determine how requests are grouped and counted. Common options include client IP address, URI, URI argument, Cookie, a specified request header, and the first or last IP address in X-Forwarded-For. Combining keys creates a more granular counting dimension. For example, the combination of client IP address and URI limits each client’s access to each endpoint independently.
Before using X-Forwarded-For as a key, ensure that requests can arrive only through trusted proxies and that those proxies overwrite or sanitize any client-supplied header with the same name. Otherwise, an attacker can forge the header to bypass rate limits or cause an incorrect block.
Rate-based actions delay or reject requests based on the number of requests per unit of time. Count-based actions total requests in a fixed time window. Set thresholds from normal traffic peaks, endpoint cost, and the acceptable burst size, then adjust them gradually after observing production behavior.
After a rejection condition is met, OpenResty Edge can close the connection, return an error page, require a CAPTCHA or JavaScript challenge, mark the request as rejected, or block an IP when supported by the selected action. For traffic that can include legitimate users, prefer a recoverable action such as a CAPTCHA. Use connection closing or IP blocking after confirming a malicious source.
The SSL handshake rate limit is enabled from the application’s SSL configuration page. For details, see Limit SSL handshake rate.
After enabling a protection rule, also enable CC attack logs to create a feedback loop of detection, handling, observation, and tuning.
In Edge Admin, open Global Config > Logs, enable CC Logs, and configure the log rate limit, protection statistics expiration time, shared memory size, buffer, and flush interval for the expected attack volume. Log rate limiting avoids writing an entry for every request during a high-rate attack and reduces load on the logging system.
After releasing the configuration, open Application > CC Logs to review triggered records. Use the client identifier, URI, handling result, and trigger frequency to determine whether the thresholds are appropriate. For configuration and testing steps, see CC Attack Logs.
Rate-limiting state is isolated by application by default and is not shared across applications. For example, after a client triggers a request rate limit in application A, it can still access application B if no limit is triggered there. This differs from using a global shared rate-limiting zone directly in NGINX.
Operating system-level IP blocking drops all packets from the source IP. Evaluate its impact against the actual network topology before enabling it.
Request rate limiting uses the leaky bucket algorithm to control the request processing rate.
Request count limiting counts the total number of requests for each key within a fixed time window.
The Delay Request action adds a fixed wait time to requests that match the page rule conditions before processing continues.
The block requests action continuously observes the request processing rate.
The Limit Response Data Rate action controls the response transfer rate for matching requests, preventing a single download, large-file response, or.
Limit SSL Handshake Rate controls how frequently a single client IP address can initiate TLS handshakes, reducing the gateway CPU and connection.
The Block Source IP action blocks the current request’s source IP at the operating system level for a specified period.
The Block IP List action checks whether a request’s source IP appears in a specified IP list.
Limit request concurrency caps the number of simultaneous requests in a key space you choose: concurrency above the shape threshold is shaped, and.