testcookie_arg

The `testcookie_arg` directive defines a GET parameter name used for determining cookie setting attempts in the NGINX testcookie robot mitigation module.

Syntaxtestcookie_arg name;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The testcookie_arg directive is crucial in the operation of the NGINX testcookie robot mitigation module, which employs a cookie-based challenge-response mechanism to thwart automated requests. This directive specifies the name of the GET parameter that is used to track how many attempts have been made to successfully set a cookie in a user's browser. Without this directive being properly configured, the server may enter an endless loop trying to set the cookie, leading to user errors and a poor experience, as the browser will handle this situation by eventually displaying an error page after multiple failed attempts.

When configured, the server verifies the specified GET parameter during each request to determine whether a cookie-setting attempt was made. If the parameter is absent or incorrectly handled, it can cause the server to repeatedly attempt to set the cookie indefinitely, as it won’t have any mechanism in place to limit the number of retry attempts. Coupled with the testcookie_max_attempts directive, which states the maximum number of allowed redirects before a fallback URL is triggered, this mechanism ensures that users aren’t stuck in an infinite loop of cookie-setting attempts but are instead redirected to an appropriate resource or notification after exceeding the set limit.

Config Example

http {
    testcookie on;
    testcookie_arg "cookie_attempt";
    testcookie_max_attempts 5;
}

Not setting the testcookie_arg may lead to infinite redirect attempts, causing browser errors.

Ensure the parameter name is used consistently throughout your application to prevent client-side issues.

If testcookie_max_attempts is set to 0, user experience may degrade as users won't be redirected after exceeding the limit.

← Back to all directives