-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: support multiple cookies with the same name across different paths and domains #14131
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
fix: support multiple cookies with the same name across different paths and domains #14131
Conversation
🦋 Changeset detectedLatest commit: 98c8565 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
@copilot not sure if you'll see this in time but it looks like you're adding options to
|
- Add generate_cookie_key function to create unique keys from domain/path/name - Extend cookies.get() to accept optional domain and path options in opts parameter - Store cookies with unique keys to prevent overwrites - Maintain backward compatibility with existing API usage - Add comprehensive tests for new functionality - Address review feedback from PR #14056 Co-authored-by: Rich-Harris <[email protected]>
- Fix formatting issues with prettier - Verify all tests pass including edge cases - Confirm TypeScript type checking passes - Complete implementation addresses all review feedback from PR #14056 Co-authored-by: Rich-Harris <[email protected]>
…cific path wins' logic Co-authored-by: Rich-Harris <[email protected]>
You're absolutely right - adding options to
The solution now correctly handles the scenario you described - |
@copilot one of the tests you added is failing. Are you able to see the logs? On my phone right now but can help debug later |
Co-authored-by: Rich-Harris <[email protected]>
Fixed the failing test - the issue was in the path specificity calculation. Previously used |
…thub.com:sveltejs/kit into pr/14131
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.
thanks copilot for the groundwork and @Avaq for the review
Fixes #13947
When setting multiple cookies with the same name but different paths or domains using
event.cookies.set()
, only the last cookie was retained. This happened because the internalnew_cookies
object used just the cookie name as the key, causing cookies with different paths/domains to overwrite each other.Example of the issue
Previously, this would only result in one
set-cookie
header:Now it correctly sends both:
Solution
${domain || ''}${path}?${name}
cookies.get()
method implements proper cookie precedence by selecting the cookie with the most specific matching path, following standard browser behaviorcookies.get(name)
automatically finds the most appropriate cookieBehavior
The solution ensures consistent behavior whether cookies are freshly set during the current request or read from existing request headers.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.