cookie_limit_req
Limits the number of malicious IP forged cookies by controlling request rates associated with specific cookies.
Description
The cookie_limit_req directive is part of the NGINX module that helps mitigate potential abuse from malicious requests by specifically targeting cookies. When this directive is applied, it specifies a previously defined shared memory zone (via cookie_limit_req_zone) and allows for controlling the number of requests that can be processed based on cookie information. This directive helps to limit the influx of requests by imposing a defined request rate and maintaining a maximum burst capacity of requests that can be processed without delay.
The zone parameter identifies the shared memory zone, which has already been defined with parameters like request rate and burst size. Additional options allow for further fine-tuning of how NGINX handles excess requests: the burst parameter defines the maximum number of requests that can exceed the specified rate before delays or terminations occur, and the nodelay setting allows immediate processing of requests up to this burst limit, instead of queuing them. This control is critical for maintaining server performance while also managing security against abuse through excessive requests initiated from the same IP or with the same cookie.
The behavior of delayed or excess requests can also be fine-tuned using the cookie_limit_req_log_level and cookie_limit_req_status directives, which dictate the logging level for these events and the status code returned for rejected requests, respectively. Overall, the cookie_limit_req directive is essential for enforcing cookie-related rate limits effectively, aiding in both performance management and protection against certain types of attacks.
Config Example
cookie_limit_req zone=two burst=30 nodelay;
Ensure the shared memory zone is defined before using this directive.
A high burst limit can lead to performance issues if not properly managed.
Using nodelay can lead to overwhelming the server if requests are consistently above the rate limit.