Skip to content

Commit

Permalink
Fix Y2038 bug for JWT on 32 bit plattforms
Browse files Browse the repository at this point in the history
Ensure the expire field is always 64-bit to prevent issues in 2038
on 32-bit platforms, where `usize` is only 32 bits wide.
  • Loading branch information
mrothNET committed Oct 11, 2024
1 parent e544fa4 commit 51ca96a
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/auth/jwt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Value>,
}

Expand Down Expand Up @@ -70,8 +70,7 @@ impl JWT {
pid: String,
claims: Option<Value>,
) -> JWTResult<String> {
#[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 };

Expand Down

0 comments on commit 51ca96a

Please sign in to comment.