testcookie_fallback

Sets the fallback URL for redirects after exceeding maximum cookie setting attempts.

Syntaxtestcookie_fallback URL;
Defaultnone
Contexthttp, server, location
Arguments1

Description

The testcookie_fallback directive in the NGINX testcookie robot mitigation module defines a URL to which a client will be redirected if the specified maximum number of attempts to set a challenge cookie is exceeded. This behavior is crucial for preventing abuse and ensuring legitimate users have a final opportunity to access content when cookie challenges fail. If the testcookie_max_attempts directive is reached, and the testcookie_fallback is not set, the client will receive a 403 Forbidden error which may not provide a satisfactory user experience.

This directive accepts a single argument that can include NGINX variable references, allowing for dynamic URL generation based on client specifics or request parameters. For example, it is possible to redirect users to a custom error page or a help document specifically tailored to their issues with cookie acceptance, thereby enhancing user experience. Proper usage of this directive can help script automated behavior for different user segments, thus improving engagement while still safeguarding against bots.

The placement of testcookie_fallback directive is flexible and can be configured within the http, server, or location context of an NGINX configuration file. This flexibility allows administrators to tailor the mitigation strategies to suit specific sites or application architecture, facilitating broader protection mechanisms while confining the mitigation to specific locations if desired.

Config Example

http {
    testcookie on;
    testcookie_max_attempts 5;
    testcookie_fallback /fallback;
    
    location /fallback {
        return 200 'Cookie setup failed, redirecting...';
    }
}

Ensure that the URL provided is accessible and correctly configured to handle the redirect; otherwise, users may encounter further errors.

Remember to define testcookie_max_attempts appropriately, as this will influence whether the fallback is triggered or not.

Be cautious about exposing sensitive data in the fallback URL via NGINX variables. Ensure it doesn't leak information unknowingly.

← Back to all directives