From 51ca96a3356b54b1b023c525198c34d54722fdf3 Mon Sep 17 00:00:00 2001 From: Michael Roth Date: Fri, 11 Oct 2024 14:11:23 +0200 Subject: [PATCH] Fix Y2038 bug for JWT on 32 bit plattforms Ensure the expire field is always 64-bit to prevent issues in 2038 on 32-bit platforms, where `usize` is only 32 bits wide. --- src/auth/jwt.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/auth/jwt.rs b/src/auth/jwt.rs index a32c424b8..8a6798fed 100644 --- a/src/auth/jwt.rs +++ b/src/auth/jwt.rs @@ -17,7 +17,7 @@ const JWT_ALGORITHM: Algorithm = Algorithm::HS512; #[derive(Debug, Serialize, Deserialize)] pub struct UserClaims { pub pid: String, - exp: usize, + exp: u64, claims: Option, } @@ -70,8 +70,7 @@ impl JWT { pid: String, claims: Option, ) -> JWTResult { - #[allow(clippy::cast_possible_truncation)] - let exp = (get_current_timestamp() + expiration) as usize; + let exp = get_current_timestamp().saturating_add(*expiration); let claims = UserClaims { pid, exp, claims };