-
Notifications
You must be signed in to change notification settings - Fork 50
feat: Add Cookie Chunking to handle large JWTs #325
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
base: main
Are you sure you want to change the base?
Conversation
7e6774c to
481ece3
Compare
nholden
left a comment
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.
Looking good! Left a couple of non-blocking thoughts.
cc @stacurry since I know you're working on documenting WorkOS cookies.
| // Delete all session cookies (base + chunks) | ||
| const allCookies = nextCookies.getAll(); | ||
| for (const cookie of allCookies) { | ||
| // Delete base cookie or any chunked cookie (cookieName.0, cookieName.1, etc.) | ||
| if (cookie.name === cookieName || (cookie.name.startsWith(`${cookieName}.`) && /\.\d+$/.test(cookie.name))) { | ||
| nextCookies.delete({ name: cookie.name, domain, path, sameSite, secure }); | ||
| } | ||
| } |
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.
Seeing some regex duplication here. Should cookie-chunker be responsible for finding the cookie names from a list of all cookies?
| request.cookies.getAll().forEach((cookie) => { | ||
| existingCookies[cookie.name] = cookie.value; | ||
| }); | ||
| const encryptedSession = readValue(cookieName, existingCookies); |
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.
Sometimes, cookie-size can be exceeded by larger JWTs, which fails with odd errors as a result of the cookie not being set.
This PR introduces a new cookie-chunking feature that will automatically break up too-large JWTs across several cookies, reassembling it seamlessly when requested.
If no chunking is required, the cookie will remain as
WORKOS_COOKIE_NAME(defaulted tosos-session. If chunking is needed it will be${WORKOS_COOKIE_NAME || 'wos-session'}.${chunkIndex}.