Fix refresh token bugs: preserve on OIDC omission, deduplicate concurrent refreshes#271
Fix refresh token bugs: preserve on OIDC omission, deduplicate concurrent refreshes#271
Conversation
…concurrent refreshes - Fix #268: Use nullish coalescing to keep existing refresh_token when OIDC provider omits it from the refresh response (per RFC 6749 §6) - Fix #269: Add per-session in-flight promise cache so concurrent requests share a single refreshTokenGrant call instead of racing - Update test mocks with sessionID to support deduplication logic https://claude.ai/code/session_012tfRZzAZk31qLhhHq33bZE
- Add MAX_INFLIGHT_REFRESHES (10,000) to prevent unbounded map growth under extreme concurrent session expiry - Add test: refresh token preserved when OIDC omits it (#268) - Add test: concurrent refresh calls deduplicated (#269) https://claude.ai/code/session_012tfRZzAZk31qLhhHq33bZE
…ogging - Refactor inflight promise to return TokenResult so each concurrent waiter updates its own user object (fixes stale-token write-back) - Add 15s timeout via Promise.race to prevent indefinite OIDC hangs - Add console.warn when inflight map reaches capacity - Add test: concurrent rejection propagates 401 to all waiters - Add assertions verifying second waiter receives fresh tokens https://claude.ai/code/session_012tfRZzAZk31qLhhHq33bZE
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
Fixes two bugs in the OIDC token refresh middleware (
isAuthenticated) that caused intermittent session invalidation. The refresh token was silently overwritten withundefinedwhen the OIDC provider omitted it from the response (violating RFC 6749 §6), and concurrent requests with expired tokens raced to callrefreshTokenGrant, invalidating rotated tokens.Closes #268, closes #269.
Changes
Refresh token preservation (bug #268)
tokens.refresh_token ?? user.refresh_token) inupdateUserSessionto preserve the existing token when the OIDC provider omits it from the refresh responseConcurrent refresh deduplication (bug #269)
inflightRefreshesMap) keyed byreq.sessionIDTokenResultso each waiter updates its ownreq.userobject (Express deserializes separate user references per request)Promise.raceprevents indefinite hangs from stalling OIDC providersconsole.warnwhen reached — degrades gracefully by skipping dedup.catch(() => {}).finally(() => delete)prevents unhandled rejections and map leaksTests
refreshTokenGrantcall)sessionIDto mock request objectsHow to test
npm run check && npm run test— all 1767 tests passnpm run build— production build succeeds