Keats / jsonwebtoken

JWT lib in rust
MIT License
1.64k stars 260 forks source link

Expiration validated incorrectly when system time is not UTC #253

Closed fayalalebrun closed 2 years ago

fayalalebrun commented 2 years ago

I noticed validation was succeeding even though the expiration of my token had passed well beforehand.

Looking at the code, the timestamp compared to exp is computed in validation.rs as follows:

pub fn get_current_timestamp() -> u64 {
    let start = SystemTime::now();
    start.duration_since(UNIX_EPOCH).expect("Time went backwards").as_secs()
}

I believe the problem is that the timestamp is obtained from SystemTime::now(). This returns a non-UTC timestamp in my system (Corresponding to the local time zone).