-
Notifications
You must be signed in to change notification settings - Fork 67
fix(nextjs): keep the ID token claims in the session cookie and switch organizations without the in-memory session #550
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
Open
DonOmalVindula
wants to merge
1
commit into
asgardeo:main
Choose a base branch
from
DonOmalVindula:fix/nextjs-cookie-backed-session
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@asgardeo/nextjs': patch | ||
| --- | ||
|
|
||
| Organization switching, the current organization and the ID-token fallback of the user profile no longer depend on the in-memory session of the underlying Node client, which is empty after a server restart, on another serverless instance, or after the middleware refreshed the tokens in the Edge runtime. The claims of the ID token are now kept in the session cookie (single-use protocol claims such as `at_hash` and `nonce` are dropped), `getDecodedIdToken()` reads them from there, and the `organization_switch` exchange uses the access token from the cookie. |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🤖 get_repo_knowledge executed:
get_repo_knowledge asgardeo/javascript /tmp/coderabbit-repo-knowledge/asgardeo-javascript-93d97855/learningsLength of output: 1843
🏁 Script executed:
Repository: asgardeo/javascript
Length of output: 22579
Sensitive Data Exposure (CWE-319): Cleartext Transmission of Sensitive Information
Reachability: Internal · Exploitability: Moderate
Require HTTPS before sending token credentials.
This request sends the access token and client credentials to the configured
tokenEndpoint. Reject non-HTTPS endpoints before callingfetch.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🤖 get_repo_knowledge executed:
get_repo_knowledge asgardeo/javascript /tmp/coderabbit-repo-knowledge/asgardeo-javascript-93d97855/learningsLength of output: 1843
🏁 Script executed:
Repository: asgardeo/javascript
Length of output: 20948
🌐 Web query:
MDN Fetch API Request redirect default follow 307 308 preserve POST body💡 Result:
The default redirect behavior for the Fetch API is to automatically follow redirects [1][2]. The
redirectoption, which defaults tofollow, determines how the browser handles server-side redirects [1][3]. Regarding POST body preservation and HTTP status codes: 1. Status Codes 307 and 308: These status codes are intended to guarantee that the request method and body are not altered during a redirect [4][5]. In the Fetch API, when a redirect is followed, the specification is designed to preserve the original method and body for 307 and 308 redirects [6]. 2. Important Nuance (Body Streams): While 307 and 308 redirects are intended to preserve the body, the Fetch API may fail with a network error if the request body is a stream that has already been consumed or cannot be replayed (e.g., if the body source is null) [4][5]. Because the Fetch API does not store the entire request body in memory by default to avoid negative performance implications, replaying a stream-based body is not always possible [4][7]. 3. Other Status Codes (301, 302, 303): In contrast to 307/308, status codes 301, 302, and 303 often trigger a conversion to a GET request, in which case the original POST body and specific request headers are stripped [6]. If you need to manually handle redirects (for example, to inspect the response before choosing whether to redirect, or to bypass automatic behavior), you can set theredirectoption tomanual[1][8]. When set tomanual, the Fetch API returns an opaque-redirect filtered response instead of automatically following the redirect [3][9].Citations:
Sensitive Data Exposure (CWE-200): Exposure of Sensitive Information to an Unauthorized Actor
Reachability: External · Exploitability: Difficult
Reject redirects for the credential-bearing token request.
A
307or308redirect can forward the POST body, includingtokenand possiblyclient_secret. Setredirect: 'error'and add a test that verifies no second token-bearing request occurs.Proposed fix
const response: Response = await fetch(tokenEndpoint, { body: body.toString(), headers: { Accept: 'application/json', 'Content-Type': 'application/x-www-form-urlencoded', ...(useBasicAuth ? {Authorization: `Basic ${btoa(`${clientId}:${clientSecret}`)}`} : {}), }, method: 'POST', + redirect: 'error', });🤖 Prompt for AI Agents