-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shouldn't time skew be subtracted in isTokenExpired? #11
Comments
Also an issue with latest release |
@spedy The goal of this setting is to allow for some time skew between client and server by giving some extra time when deciding if a token is already expired. The goal is not to precisely estimate which skew is there and then correct for it. |
But shouldn't this be consolidated with your backend code? You are checking if the expiration of the token is within this interval, so in your JS code you should probably do the same. Like so
|
When deciding if a token is expired, you just need to check if the expired timestamp is smaller than some given value, not if it is bigger than some given value. |
But you are not taking into account that time skew is non-negative and that either the client can lag or the server can lag. That's why there is the interval. |
Again, the goal is not to estimate the exact skew. You just want to know if a token expired in the past and for that, you just need to check if the expired timestamp is smaller than some given value. The other direction would be interesting for the |
Ok makes sense, hopefully BE and FE code are consolidated. Here is my specific case when putting laptop for sleep and logging in the computer after 60 seconds.
TimeSkew before logout was 0, after logging in after cca 60s it was 61. But the server and client time were synchronized. Value sources:
So it might look like the timeSkew is not reinitiated properly in my case. @sschu so the problem is here In our code we use onTokenExpired to update the token, so when browser tab is running in the background the events are still firing. Consequently the timeSkew variable is updated here: But when we put the computer to sleep, and we wake it up, the iat is set 60 seconds ago, so the timeSkew is around 60. The expiration time of our token is set to around 1 minute for testing purposes and our token has actually expired but isTokenExpired() returns false, because iat was from before we put the computer to sleep. So I believe clearing timeSkew somehow would solve it |
This is certainly a bug. The |
Due to the amount of issues reported by the community we are not able to prioritise resolving this issue at the moment. If you are affected by this issue, upvote it by adding a 👍 to the description. We would also welcome a contribution to fix the issue. |
Due to lack of updates in the last 180 days this issue will be automatically closed. |
Before reporting an issue
Area
token-exchange
Describe the bug
Timeskew is a non negative value and is the difference between the server and the client in seconds. Then it should be subtracted not added like in your isTokenExpired code here:
https://github.com/keycloak/keycloak/blob/67b6cf7eac986f8247f77b0a51c66a1fc4151a38/js/libs/keycloak-js/src/keycloak.js#L617C13-L617C23
Version
19.0.3
Regression
Expected behavior
isTokenExpired should be truthfull
Actual behavior
isTokenExpired sometimes give me false instead of true
How to Reproduce?
Set tokenExpiration to 1 minute in keycloak admin, let the time skew be around 46 seconds, then login to your web app with keycloak-js. Close the computer for a minute. Then open it and you'll get 401 unauthorized requests on your non-keycloak server requests.
Anything else?
No response
The text was updated successfully, but these errors were encountered: