set_decrypt_session

The set_decrypt_session directive is used to decrypt a session variable in NGINX, enabling access to original variable values from encrypted data.

Syntaxset_decrypt_session variable_name encrypted_variable_name;
Defaultnone
Contexthttp, server, location, if in server, if in location
Arguments1-2

Description

The set_decrypt_session directive facilitates the decryption of session data that has been previously encrypted within NGINX. This directive is part of the encrypt and decrypt NGINX variable values module, which relies on AES-256 encryption for data protection. When invoked, it takes one or two arguments: the first is the newly set variable that will store the decrypted value, and the second is the encrypted session variable that is to be decrypted. The behavior of this directive includes the necessary checks to ensure that the decryption process does not expose vulnerabilities or lead to bad session handling, making it pivotal for secure web applications that require user data handling.

When configuring this directive, it is mandatory to set appropriate encryption keys and initialization vectors using the associated directives, such as encrypted_session_key and encrypted_session_iv. Failure to appropriately set these related directives may result in decryption errors or security issues. It is commonly used in conjunction with other modules, such as ngx_set_misc, to manipulate and control how encrypted data is used in NGINX, thereby enhancing the capabilities of session management in web applications.

Config Example

location /decrypt {
    set $encrypted_data $cookie_my_login;
    set_decrypt_session $raw_data $encrypted_data;

    if ($raw_data = '') {
        return 401; # unauthorized
    }
    # Process the request with the raw data...
}

Ensure that the encryption key and IV are correctly configured; mismatches will cause decryption failures.

The directive does not handle errors gracefully by default; implement custom error handling for empty or invalid results from decryption.

← Back to all directives