testcookie_port_in_redirect

The 'testcookie_port_in_redirect' directive specifies whether the redirect URI should include the port number when setting challenge cookies.

Syntaxtestcookie_port_in_redirect on | off;
Defaultoff
Contexthttp, server, location
Arguments1

Description

The 'testcookie_port_in_redirect' directive is a feature of the NGINX testcookie robot mitigation module designed to enhance cookie-based validation mechanisms by controlling the behavior of redirect URIs. When enabled, the directive ensures that any HTTP redirect responses generated during the challenge-response process include the port number in the 'Location' header, which can be particularly useful for services listening on non-standard ports. This could be critical for applications that differentiate between HTTP and HTTPS or have specific port-based routing configurations. The inclusion of the port number can help avoid potential issues where clients might fail to set the cookie properly due to redirecting to a URI that is not explicitly defined with its service port.

The directive accepts a single parameter, which is typically a boolean value indicating whether the port should be included in the redirect. If set to 'on', the port is included; if 'off', the port is omitted from the redirect URI. This flexibility allows administrators to tailor the cookie setting behavior based on their specific deployment needs and infrastructure configuration, enhancing compatibility with various client setups and mitigating common issues related to redirection and cookie handling.

Config Example

http {
    testcookie on;
    testcookie_port_in_redirect on;
    # other directives...
}

If not configured properly, enabling this directive could lead to misbehaving applications that do not expect a port in the redirect URI.

Ensure that the backend services and proxies are properly handling the redirects with port numbers to avoid confusion for clients. Adjusting this setting without considering client and server configurations could result in cookie parsing failures.

← Back to all directives