auth_jwt_alg

The 'auth_jwt_alg' directive specifies the algorithm used for validating JSON Web Tokens (JWT) within NGINX.

Syntaxauth_jwt_alg HS256 | HS384 | HS512 | RS256 | RS384 | RS512 | ES256 | ES384 | ES512 | any;
Defaultany
Contexthttp, server, location
Arguments1

Description

The 'auth_jwt_alg' directive is used in NGINX configurations to define the cryptographic algorithm employed for verifying JSON Web Tokens (JWT). The directive takes a single argument that corresponds to one of several supported algorithms, including HS256, HS384, HS512, RS256, RS384, RS512, ES256, ES384, ES512, or 'any', which allows for flexibility in selecting the validation process. Typically, these algorithms are employed based on the type of signing keys used—either symmetric or asymmetric keys—during JWT creation.

When processing incoming requests, if the 'auth_jwt' directive is enabled, NGINX will utilize the specified algorithm to validate the JWT signature. This verification process is crucial for ensuring that the token has not been tampered with and is legitimate, which helps to maintain secure access to resources. The directive can be set at various contexts within the NGINX configuration: 'http', 'server', or 'location', making it versatile for handling different request scopes. By default, the behavior defaults to using a non-specific algorithm (JWT_ALG_ANY) if not explicitly set.

Using 'auth_jwt_alg' allows system administrators to align their JWT handling mechanisms with industry standards, ensuring robust security practices. The successful validation of a JWT not only authenticates the user but can also carry claims related to access control or user privileges, enhancing the overall security model within the server environment.

Config Example

http {
    server {
        auth_jwt_key "your-secret-key" hex;
        auth_jwt_alg HS256;
        location /protected {
            auth_jwt on;
        }
    }
}

Ensure that the specified algorithm matches the one used to sign the JWT, or validation will fail.

Using 'any' may pose a security risk if the tokens have varying signing algorithms; prefer specific algorithms when possible.

← Back to all directives