René's URL Explorer Experiment


Title: clerk-js: SessionTokenCache serves server-expired session tokens when the device clock runs behind (regression of #672) · Issue #10185 · clerk/javascript · GitHub

Open Graph Title: clerk-js: SessionTokenCache serves server-expired session tokens when the device clock runs behind (regression of #672) · Issue #10185 · clerk/javascript

X Title: clerk-js: SessionTokenCache serves server-expired session tokens when the device clock runs behind (regression of #672) · Issue #10185 · clerk/javascript

Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk support via email or Discord This issue ...

Open Graph Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ...

X Description: Preliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ...

Opengraph URL: https://github.com/clerk/javascript/issues/10185

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"clerk-js: SessionTokenCache serves server-expired session tokens when the device clock runs behind (regression of #672)","articleBody":"### Preliminary Checks\n\n- [x] I have reviewed the documentation: https://clerk.com/docs\n- [x] I have searched for existing issues: https://github.com/clerk/javascript/issues\n- [x] I have not already reached out to Clerk support via email or Discord\n- [x] This issue is not a question, general help request, or anything other than a bug report directly related to Clerk.\n\n### Reproduction\n\nhttps://gist.github.com/AKhozya/06c6aab6ed3416e50fc8227823ac0a6c\n\n### Publishable key\n\nNot included: the bug is in clerk-js's token cache and does not depend on an instance. Happy to share one if it helps.\n\n### Description\n\nIf the device clock runs behind the server, `SessionTokenCache.get()` keeps returning a session token after the token has expired by server time. Once the token is more than 5 s past `exp`, the backend's default allowance (`DEFAULT_CLOCK_SKEW_IN_MS`, `packages/backend/src/jwt/verifyJwt.ts:20`) rejects it.\n\n**Cause.** When a token resolves, `tokenCache.ts:411` sets `live.createdAt = issuedAt`, the JWT `iat` in server time. `get()` (line 194) computes `elapsed = deviceNow - createdAt`, so `remainingTtl = (exp - iat) - (deviceNow - iat) = exp - deviceNow`. That compares server time with device time directly. If the device runs S seconds behind, the cache serves the token for S seconds after it expired. The deletion timer (line 409, `expiresAt - deviceNow`) fires S seconds late as well.\n\n**History.**\n\n| PR | Merged | Change to `tokenCache.ts` |\n|---|---|---|\n| #672 | 2023-01-27 | \"Account for user clock skew in TokenCache\": `createdAt` from the device clock at caching time, so elapsed time is measured on one clock |\n| #7317 | 2026-01-30 | \"Proactive session token refresh\": `value.createdAt = issuedAt` |\n| #9030 | 2026-07-03 | keeps it as `live.createdAt = issuedAt` |\n\n`protectSession.ts:291` already describes this hazard for another store and avoids it by measuring elapsed time on one clock.\n\n**Steps to reproduce:** apply the test from the gist to `packages/clerk-js/src/core/__tests__/tokenCache.test.ts` on main `44b09ba` and run that file.\n\n1. The server issues a token at T with a 60 s lifetime.\n2. The device clock reads T − 40 when the token is cached.\n3. Advance 50 s: `get()` returns the token (correct, 10 s remain).\n4. Advance 20 s more: by server time the token expired 10 s ago.\n\n**Expected behavior:** at step 4, `get()` returns `undefined`, as it does in the control test with no skew.\n\n**Actual behavior:** at step 4, `get()` still returns the token. Result: `Tests 1 failed | 69 passed (70)`; only the skew test fails.\n\n**Effect in an app.** Our Expo app sends the session token to our own Express backend, which calls `verifyToken` and answers a failed verification with 401.\n\n| Emulator clock | Chat sends that failed |\n|---|---|\n| 36 s behind the host | about 5 of 15, each with the app's error for an HTTP 4xx other than 429 (status not captured) |\n| resynced to the host | 0 of 10 |\n\nOur workaround, not yet deployed: `clockSkewInMs: 60_000` on `verifyToken`, and one retry with `getToken({ skipCache: true })` after a 401.\n\n**On a fix.** If `createdAt` takes the device clock when the token resolves, the new test passes. #672 uses the device clock at caching time. If a token is already partway through its lifetime when it reaches the cache, `get()` counts its full lifetime from that moment. If the clocks agree, the deletion timer (`exp` minus device time) still evicts such a token at its real expiry, so `get()` serves it late only if that timer runs late. It also fails one existing test, `broadcast resilience > a failing postMessage does not evict the freshly cached token`, because that test's fixture has `iat` after `exp`. A fix that handles both a device clock running behind and a token that reaches the cache partway through its lifetime may need the offset between the server clock and the device clock, for example measured when a token is freshly minted. We have not tested such a fix.\n\n### Environment\n\n| Item | Value |\n|---|---|\n| `@clerk/expo` | 4.6.9 |\n| `@clerk/clerk-js` installed | 6.33.0; its built bundle sets the cache entry's `createdAt` to the token's `iat` |\n| clerk/javascript commit tested | main `44b09ba` |\n| Expo | SDK 57 |\n| React Native | 0.86.3 |\n| Device | Android emulator, system image android-37.1 |\n","author":{"url":"https://github.com/AKhozya","@type":"Person","name":"AKhozya"},"datePublished":"2026-10-09T21:48:13Z","url":"https://github.com/clerk/javascript/issues/10185"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:dd1fb862-b657-75fc-abb0-a4163cefef16
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDF32:9464C:1290C54:195A48A:6AFB6DA1
html-safe-nonce61fafae34cacfbbfa9ec504ae99c8fbfcd8cd3b8c2ecc21a146cb4a32242f0c2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERjMyOjk0NjRDOjEyOTBDNTQ6MTk1QTQ4QTo2QUZCNkRBMSIsInZpc2l0b3JfaWQiOiIzNDQ4NTY2ODUwMjEwNDU5MDQxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac93031a6fdb87143c09edee06ecb87762b0704aee8c6c3cf18ba3d935cb436dce
hovercard-subject-tagissue:5785079358
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/clerk/javascript/10185/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0eface708f9ae1e973c562fc0b1720fa0a5d5de55bb9e9d551829617ffe6e961/clerk/javascript/issues/10185
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0eface708f9ae1e973c562fc0b1720fa0a5d5de55bb9e9d551829617ffe6e961/clerk/javascript/issues/10185
og:image:altPreliminary Checks I have reviewed the documentation: https://clerk.com/docs I have searched for existing issues: https://github.com/clerk/javascript/issues I have not already reached out to Clerk ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameAKhozya
hostnamegithub.com
expected-hostnamegithub.com
Nonecca289ecd54650fcf3c0b037a58b97186dee2cc4406819d87fab93728fd83700
turbo-cache-controlno-preview
go-importgithub.com/clerk/javascript git https://github.com/clerk/javascript.git
octolytics-dimension-user_id49538330
octolytics-dimension-user_loginclerk
octolytics-dimension-repository_id438331492
octolytics-dimension-repository_nwoclerk/javascript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id438331492
octolytics-dimension-repository_network_root_nwoclerk/javascript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release88808b1fae5ab8a526a73e7ce5542a10eb9d6971
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/clerk/javascript/issues/10185#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fclerk%2Fjavascript%2Fissues%2F10185
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fclerk%2Fjavascript%2Fissues%2F10185
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=clerk%2Fjavascript
Reloadhttps://github.com/clerk/javascript/issues/10185
Reloadhttps://github.com/clerk/javascript/issues/10185
Reloadhttps://github.com/clerk/javascript/issues/10185
clerkhttps://github.com/clerk
javascripthttps://github.com/clerk/javascript
Codehttps://github.com/clerk/javascript
Issues45 (45)https://github.com/clerk/javascript/issues
Pull requests110 (110)https://github.com/clerk/javascript/pulls
Discussionshttps://github.com/clerk/javascript/discussions
Actionshttps://github.com/clerk/javascript/actions
Security and quality6 (6)https://github.com/clerk/javascript/security
Insightshttps://github.com/clerk/javascript/pulse
https://github.com/clerk/javascript
New issuehttps://github.com/login?return_to=https://github.com/clerk/javascript/issues/10185
New issuehttps://github.com/login?return_to=https://github.com/clerk/javascript/issues/10185
#10401https://github.com/clerk/javascript/pull/10401
clerk-js: SessionTokenCache serves server-expired session tokens when the device clock runs behind (regression of #672)https://github.com/clerk/javascript/issues/10185#top
#10401https://github.com/clerk/javascript/pull/10401
https://github.com/AKhozya
AKhozyahttps://github.com/AKhozya
on Oct 9, 2026https://github.com/clerk/javascript/issues/10185#issue-5785079358
https://clerk.com/docshttps://clerk.com/docs
https://github.com/clerk/javascript/issueshttps://github.com/clerk/javascript/issues
https://gist.github.com/AKhozya/06c6aab6ed3416e50fc8227823ac0a6chttps://gist.github.com/AKhozya/06c6aab6ed3416e50fc8227823ac0a6c
#672https://github.com/clerk/javascript/pull/672
#7317https://github.com/clerk/javascript/pull/7317
#9030https://github.com/clerk/javascript/pull/9030
#672https://github.com/clerk/javascript/pull/672
wobsorianohttps://github.com/wobsoriano
completedhttps://github.com/clerk/javascript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#10401https://github.com/clerk/javascript/pull/10401
on Oct 27, 2026https://github.com/clerk/javascript/issues/10185#event-34376865044
Sign up for freehttps://github.com/signup?return_to=https://github.com/clerk/javascript/issues/10185
Sign in to commenthttps://github.com/login?return_to=https://github.com/clerk/javascript/issues/10185
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.