-
Notifications
You must be signed in to change notification settings - Fork 57
refactor: drop cookie sealing with bidirectional migration #424
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
nicknisi
wants to merge
5
commits into
main
Choose a base branch
from
feat/drop-session-sealing
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
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c715f46
refactor: drop cookie sealing with bidirectional migration
nicknisi 437c297
chore: formatting
nicknisi 90adb02
fix: URL-encode session cookie value in raw Set-Cookie header
nicknisi 748ce46
chore: formatting
nicknisi 84f9aad
refactor: make WORKOS_COOKIE_PASSWORD optional
nicknisi 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
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
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
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
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
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
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.
🔴 Raw JSON in Set-Cookie header breaks when session data contains semicolons
After the migration from
sealData(which produces URL-safe base64) toJSON.stringify, the raw JSON output is placed directly into aSet-Cookieheader at line 319 without URL-encoding. If any session field (e.g., user'sfirstName,lastName,email, ormetadata) contains a semicolon (;), the browser's cookie parser will interpret it as a cookie attribute delimiter, truncating the cookie value. This produces malformed JSON that fails to parse on subsequent requests, causing session loss.Demonstration of the truncation
For a user with
firstName: "John; Drop", the Set-Cookie header becomes:The browser parses the value as
{"accessToken":"eyJ...","user":{"firstName":"John— everything after the first;in the JSON is treated as cookie attributes. The stored cookie is malformed JSON thatdecryptSessioncannot parse.Note that
saveSession(src/session.ts:640) usesnextCookies.set()which internally URL-encodes the value via thecookiepackage'sserializefunction, so it is not affected. Only the middleware refresh path at line 319, which manually constructs the raw header string, is vulnerable.(Refers to line 319)
Was this helpful? React with 👍 or 👎 to provide feedback.
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.
Good catch — this was a real gap. The
saveSessionpath was safe (nextCookies.setURL-encodes internally), but this middleware refresh path built the header string manually.Fixed in 91654ee — the value is now wrapped in
encodeURIComponent(). The cookie read side (request.cookies.get()/nextCookies.get()) auto-decodes, sodecryptSessionreceives raw JSON as expected.For reference, authkit-session was already safe here — its
serializeCookiehelper usesencodeURIComponent(value)at the serialization layer.