Jwt None Algorithm in Axum
How Jwt None Algorithm Manifests in Axum
JSON Web Tokens (JWT) are commonly used for stateless authentication in REST APIs. When a JWT is signed with an algorithm identifier (alg), the verifier expects the token to include a valid cryptographic signature using that algorithm. A "none" algorithm attack exploits a flaw where the verifier treats the alg header value of none as a valid signing algorithm, allowing unauthenticated requests to pass verification if the verifier does not enforce a specific signing algorithm.
In Axum, JWT handling is typically implemented using libraries such as axum-jwt, jsonwebtoken, or jwt-advanced. Attackers often target endpoints that accept JWTs via the Authorization header and may manipulate the alg claim to none to bypass signature validation.
Axum does not natively enforce algorithm validation; this responsibility falls on the JWT verification middleware. If the verification logic reads the alg header or payload claim and conditionally skips signature checks when alg is none, the application becomes vulnerable. Common patterns include:
- Directly checking
jwt.algwithout enforcing a whitelist of allowed algorithms. - Using a verification function that only checks token structure but ignores the
algfield. - Allowing tokens with
alg:noneto pass if the signature is empty or omitted.
These patterns can manifest in Axum route handlers when JWT verification is performed manually or via a custom extractor that does not validate the algorithm. For example, an endpoint may accept any token that parses without throwing an error, regardless of signing method. This is especially dangerous in APIs that rely on JWT for role-based access control (RBAC) or session management.
Because Axum is a low-level, modular framework, developers often implement JWT middleware manually. This flexibility increases the risk of misconfiguration, particularly when security assumptions are not explicitly enforced. The absence of a centralized, opinionated JWT policy means that teams must carefully audit their verification logic to prevent alg: none bypasses.
Attackers can exploit this by sending a JWT with header {