Skip to content

Commit 11364e5

Browse files
Explicitly check JWT expiration timestamp
1 parent f78c199 commit 11364e5

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/auth.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,19 @@ pub fn validate_jwt(jwt: &str) -> Result<i64, String> {
8989
let Some(secret) = SECRET_KEY.get() else {
9090
return Err("Auth module not initialized".to_string());
9191
};
92+
9293
let key = DecodingKey::from_secret(secret);
9394
let validation = get_validator(None);
9495
let Ok(token) = jsonwebtoken::decode::<Claims>(jwt, &key, &validation) else {
9596
return Err("Bad JWT".to_string());
9697
};
98+
99+
// I don't 100% trust this crate to validate the expiration timestamp, so do it manually
100+
let now = get_current_timestamp();
101+
if token.claims.exp < now {
102+
return Err("Expired JWT".to_string());
103+
}
104+
97105
match token.claims.sub.parse() {
98106
Ok(id) => Ok(id),
99107
Err(e) => Err(format!("Bad account ID: {}", e)),

0 commit comments

Comments
 (0)