Rust Jwt Lack Of Expiration
Description
This vulnerability detector identifies JWT (JSON Web Token) encoding operations in Rust code that lack proper expiration claims. JWTs without expiration times remain valid indefinitely, creating a security risk where compromised tokens cannot be naturally expired and may be used for unauthorized access long after they should have become invalid.
Detection Strategy
• Code must import the 'jsonwebtoken' library or have it as a dependency prefix
• The detector identifies calls to JWT encoding functions from the jsonwebtoken library
• For each JWT encode call, it analyzes the claims parameter to check if an expiration field ('exp') is present
• A vulnerability is reported when a JWT encode operation is found that does not include an expiration claim in the token payload
• The detection specifically looks for missing 'exp' claims which are the standard way to set token expiration times in JWT specifications
Vulnerable code example
use jsonwebtoken::{encode, EncodingKey, Header};
use serde::Serialize;
#[derive(Serialize)]
struct Claims {
sub: String,
role: String,
// Missing exp field - JWT never expires...✅ Secure code example
use jsonwebtoken::{encode, EncodingKey, Header};
use serde::Serialize;
#[derive(Serialize)]
struct Claims {
sub: String,
role: String,
exp: usize, // Added expiration field...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.