Skip to content

Commit

Permalink
fix: sort chunked session cookies (#7736)
Browse files Browse the repository at this point in the history
Update cookie.ts
  • Loading branch information
kilakewe authored Jun 5, 2023
1 parent 2318e44 commit 925a52e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/core/src/lib/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,17 @@ export class SessionStore {
* The JWT Session or database Session ID
* constructed from the cookie chunks.
*/
get value() {
return Object.values(this.#chunks)?.join("")
get value() {
// Sort the chunks by their keys before joining
const sortedKeys = Object.keys(this.#chunks).sort((a, b) => {
const aSuffix = parseInt(a.split(".")[1] || "0");
const bSuffix = parseInt(b.split(".")[1] || "0");

return aSuffix - bSuffix;
});

// Use the sorted keys to join the chunks in the correct order
return sortedKeys.map(key => this.#chunks[key]).join("");
}

/** Given a cookie, return a list of cookies, chunked to fit the allowed cookie size. */
Expand Down

1 comment on commit 925a52e

@vercel
Copy link

@vercel vercel bot commented on 925a52e Jun 5, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.