Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ pub(crate) fn validate(claims: ClaimsForValidation, options: &Validation) -> Res
if options.validate_exp || options.validate_nbf {
let now = get_current_timestamp();

if matches!(claims.exp, TryParse::Parsed(exp) if exp < options.reject_tokens_expiring_in_less_than)
{
return Err(new_error(ErrorKind::InvalidToken));
}

if matches!(claims.exp, TryParse::Parsed(exp) if options.validate_exp
&& exp - options.reject_tokens_expiring_in_less_than < now - options.leeway )
{
Expand Down Expand Up @@ -817,4 +822,17 @@ mod tests {
let res = validate(deserialize_claims(&claims), &validation);
assert!(res.is_ok());
}

// https://github.com/Keats/jsonwebtoken/issues/388
#[test]
#[wasm_bindgen_test]
fn doesnt_panic_with_leeway_overflow() {
let claims = json!({ "exp": 1 });

let mut validation = Validation::new(Algorithm::HS256);
validation.reject_tokens_expiring_in_less_than = 100;

let res = validate(deserialize_claims(&claims), &validation);
assert!(res.is_err());
}
}