testcookie_secret

The testcookie_secret directive sets a static secret key used in the computation of challenge cookies for the NGINX testcookie robot mitigation module.

Syntaxtestcookie_secret string;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The testcookie_secret directive is crucial for establishing a secure mechanism for generating challenge cookies aimed at distinguishing human traffic from automated bots. This directive accepts a single argument, which is a string that should ideally be at least 32 bytes long, to maximize security. A longer secret is recommended, as it helps in maintaining the integrity of cookies between server restarts, ensuring that legitimate users do not experience interruption in their sessions due to cookie resets caused by changes in the secret.

When this directive is set to "random," it instructs NGINX to generate a new secret key every time the server starts. While this might seem appealing for security purposes, it is discouraged because all challenge cookies generated with the old key become invalid, leading to potential access issues for legitimate users as their cookies are rendered unusable after a server restart. Therefore, it is advised to use a consistent static key to provide a stable experience for users while still protecting against automated requests.

The testcookie_secret directive should be configured appropriately within the http, server, or location contexts in your NGINX configuration file, allowing for different configurations based on the desired scope of application. Correctly managing this parameter contributes significantly to the effectiveness of the challenge/response mechanism employed by the testcookie module.

Config Example

http {
    testcookie_secret "my_static_secret_12345678901234567890123456789012";
}

Using "random" for the secret will invalidate all existing cookies on server restarts, affecting legitimate users.

Ensure the secret is at least 32 bytes to maintain sufficient security levels.

Not specifying the secret may lead to cookie generation failures, rendering the mitigation ineffective.

← Back to all directives