localStorage expiresIn
out of sync with JWT exp
#1259
Labels
bug
A problem that needs to be fixed for the feature to function as intended.
known-issue
Issue is already known and is either being investigated or is already fixed.
Milestone
Library
msal@1.2.1
@azure/msal-browser@2.x.x
@azure/msal-angular@0.x.x
@azure/msal-angular@1.x.x
@azure/msal-angularjs@1.x.x
Framework
No framework.
Description
We’re seeing instances where MSAL's
expiresIn
value stored inlocalStorage
differs quite a bit from theexp
value in the JWT token (sometimes in the minutes, sometimes in the hours/days range).If a user gets into a state where
exp
is in the past, andexpiresIn
is in the future, callingacquireTokenSilent
will consistently give you an expired token (cause it checks the value inexpiresIn
, and not the value inexp
), so there's no way for a user to get out of that state without manually deletinglocalStorage
.The root cause is that
exp
value is calculated on the server, whereasexpiresIn
is calculated after-the-fact on the client, using their system clock.We've seen the biggest difference between the two values when users put our tab in the background, or their computers to sleep. Chrome seems to throttle/pause code execution and/or network requests, and if that happens between the time you get a token back from the server, and the time when
expiresIn
value is calculated, you can get huge drift. We had a user whose JWTexp
value was a Friday, and hislocalStorage
expiresIn
value was a Monday.This is where MSAL.js relies on the system clock:
microsoft-authentication-library-for-js/lib/msal-core/src/UserAgentApplication.ts
Line 1381 in 1212c64
Security
No.
Regression
No. This problem is even present in ADAL.js. Here's where ADAL.js relies on the system clock: https://github.com/AzureAD/azure-activedirectory-library-for-js/blob/de375da0f438018f01c6902f6dcfaedb24f91320/lib/adal.js#L1661
Configuration
Reproduction steps
setInterval
localStorage
periodically, so that you force the server to send you a new tokenExpected behavior
No drift, or a way to get out of this scenario.
expiresIn
, and just relying on JWT'sexp
value. I hear you're working on encrypting tokens, so this may not be possible.Browsers
We see it happen relatively frequently with Chrome, but I see no reason why it wouldn't affect other browsers.
The text was updated successfully, but these errors were encountered: