fix(auth): prevent nil pointer panic in refreshSession with cookie-based tokens#654
Merged
omercnet merged 2 commits intodescope:mainfrom Jan 5, 2026
Merged
Conversation
When tokens are managed via cookies instead of response body, extractTokens returns empty, leaving sToken as nil. This caused a panic at line 444 when accessing info.SessionToken.RefreshExpiration. The fix adds cookie extraction logic for sToken (session token) when it's nil, mirroring the existing fallback logic for refreshToken. Also adds a dedicated test for the cookie-only token scenario. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a critical nil pointer panic in refreshSession (and selectTenant) that occurs when tokens are delivered via cookies instead of the response body. When SessionJWTViaCookie is enabled, the response body contains only cookie metadata (path, domain) without the actual JWT tokens, causing extractTokens to return an empty array and leaving sToken as nil.
Key Changes:
- Added session token extraction from cookies when
sTokenis nil or empty - Consolidated token extraction into a single cookie loop for both session and refresh tokens
- Added comprehensive test coverage for the cookie-only token scenario
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| descope/internal/auth/auth.go | Adds cookie-based session token extraction (lines 816-823) and consolidates cookie extraction loop to handle both session and refresh tokens efficiently |
| descope/internal/auth/auth_test.go | Adds test case TestRefreshSessionWithTokenViaCookie that validates the fix by simulating a response with tokens only in cookies and no tokens in the response body |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Add early loop exit when both tokens are found - Add RefreshExpiration assertion in test 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
auto-merge was automatically disabled
January 5, 2026 12:14
Head branch was pushed to by a user without write access
shilgapira
approved these changes
Jan 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
refreshSessionwhen tokens are managed via cookies instead of response bodySessionJWTViaCookieis enabled,extractTokensreturns empty results, leavingsTokenasnilinfo.SessionToken.RefreshExpiration = token.ExpirationRoot Cause
In
generateAuthenticationInfoWithRefreshToken:extractJWTResponseandextractTokensreturn 0 tokens when tokens are delivered via cookiessTokenremainsnilafter the token extraction looprefreshTokenfrom cookies (lines 816-826), but was missing the same forsTokenrefreshSession, accessinginfo.SessionToken.RefreshExpirationpanicsFix
Added session token extraction from cookies when
sTokenis nil, combined into a single loop with the existing refresh token extraction for efficiency.Test plan
TestRefreshSessionWithTokenViaCookie- tests the cookie-only token scenario🤖 Generated with Claude Code