testcookie_path

The `testcookie_path` directive specifies the cookie path for challenge cookies in the NGINX testcookie robot mitigation module.

Syntaxtestcookie_path value;
Default/
Contexthttp, server, location
Arguments1

Description

The testcookie_path directive allows you to define the path attribute of the cookie that is set by the NGINX testcookie robot mitigation module. This attribute is crucial for controlling the scope of the cookie within a web application, as it determines the URLs to which the cookie will be sent. By adjusting the path value, you can effectively isolate cookie storage for different parts of your application, enabling the use of varying keys for different locations if necessary. For example, a path of /app1/ will restrict the cookie's validity to that path, ensuring it is not sent to other sections of the site. When not defined, the default value of / means the cookie is accessible across the entire domain.

The directive can be used at different levels including http, server, and location, providing flexibility depending on the scope at which you wish to enforce cookie behavior. To set the path, one simply assigns a desired string value to the directive, such as /api/ or /users/. Understanding the interaction of this directive with other cookie settings, such as testcookie_domain and testcookie_expires, is essential for properly configuring cookie management in conjunction with the challenge-response mechanism of the testcookie module.

Config Example

server {
    location /app1 {
        testcookie_path /app1/;
        testcookie on;
    }
    location /app2 {
        testcookie_path /app2/;
        testcookie on;
    }
}

Ensure the specified path is correct; misconfiguration can lead to cookies not being sent for requests to specific paths.

Be mindful of the path specificity; a more specific path will override a less specific one, which could lead to unintended behavior.

← Back to all directives