Skip to content

Conversation

1egoman
Copy link
Contributor

@1egoman 1egoman commented Oct 10, 2025

I happened to notice a bug in the token source token expiry checking logic that slipped through the original pull request, so I fixed it and added some tests (which I really should have done in the first place 😬 ) to make sure this doesn't regress again.

Copy link

changeset-bot bot commented Oct 10, 2025

🦋 Changeset detected

Latest commit: 9e42aad

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
livekit-client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Contributor

github-actions bot commented Oct 10, 2025

size-limit report 📦

Path Size
dist/livekit-client.esm.mjs 82.96 KB (0%)
dist/livekit-client.umd.js 91.51 KB (+0.06% 🔺)

Comment on lines 17 to 22
return expiresAt >= now;

const nbfInMilliseconds = jwtPayload.nbf * ONE_SECOND_IN_MILLISECONDS;
const nbfDate = new Date(nbfInMilliseconds);

const expInMilliseconds = jwtPayload.exp * ONE_SECOND_IN_MILLISECONDS;
const expDate = new Date(expInMilliseconds - ONE_MINUTE_IN_MILLISECONDS);

const isValid = nbfDate <= now && expDate > now;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main bug was this return expiresAt >= now; line was backwards. It should have actually been return expiresAt < now;.

So, I fixed this and also at the same time added some logic to check the nbf field in the jwt to make sure that it's valid in the other direction.

@1egoman 1egoman marked this pull request as ready for review October 10, 2025 16:27
@1egoman 1egoman requested a review from lukasIO October 10, 2025 16:27
Copy link

@xianshijing-lk xianshijing-lk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, just one nit, please feel free to ignore

const expInMilliseconds = jwtPayload.exp * ONE_SECOND_IN_MILLISECONDS;
const expDate = new Date(expInMilliseconds - ONE_MINUTE_IN_MILLISECONDS);

return nbfDate <= now && expDate > now;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit, I think it will be slightly cleaner if we use sec rather than ms, for instance:

const nowSec = Date.now() / 1000;
const validFrom = jwtPayload.nbf;
const validUntil = jwtPayload.exp - 60; // 1 minute buffer
return nowSec >= validFrom && nowSec < validUntil;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants