Skip to content

Commit

Permalink
fix: check JWT expiration for extra leniency
Browse files Browse the repository at this point in the history
  • Loading branch information
barabo authored Sep 10, 2021
1 parent 25d3730 commit d3ae416
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/TokenHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,10 @@ class TokenHandler extends SMARTHandler {
if (key.kid !== validated.header.kid) {
console.error(`Expected JWT kid (${validated.header.kid}) to match (${key.kid})`);
}
const now = Math.floor(Date.now() / 1000);
if (now > payload.exp) {
console.error(`${now}: JWT expired at ${payload.exp}, ${now - payload.exp} seconds ago`);
const fiveMinutesFromNow = Math.floor(Date.now() / 1000) + 300;
if (payload.exp > fiveMinutesFromNow) {
const error = `JWT expiration (${payload.exp}) is too permissive, should be no greater than 5 minutes.`;
console.error(error);
}
if (payload.iss !== payload.sub) {
console.error(`Mismatched JWT iss (${payload.iss}) != sub (${payload.sub})`);
Expand Down

0 comments on commit d3ae416

Please sign in to comment.