Repository navigation
fix(eio-client): send same-origin cookies with the fetch() transport - #5607
Open
mark1russell7 wants to merge 1 commit into
Open
mark1russell7 wants to merge 1 commit into
mark1russell7 wants to merge 1 commit into
Conversation
With `withCredentials: false` (the default), the fetch() transport used the "omit" credentials mode, which drops the cookies even for same-origin requests and ignores the Set-Cookie headers of the responses. The XHR transport sends them, so sticky-session cookies (load balancer, `cookie` option of the server) were lost when switching to fetch(). The "same-origin" mode matches the XHR behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The kind of change this PR does introduce
Current behavior
With
withCredentials: false(the default), theFetchtransport callsfetch()withcredentials: "omit". This mode drops the cookies also for same-origin requests, and ignores theSet-Cookieheaders of the responses. TheXHRtransport sends the same-origin cookies, so sticky-session cookies (of a load balancer, or of thecookieoption of the server) are lost when an application switches toFetch.New behavior
The
Fetchtransport usescredentials: "same-origin"whenwithCredentialsisfalse, which is the behavior ofXMLHttpRequestwithwithCredentials = false: cookies for same-origin requests, no cookies for cross-origin requests. WithwithCredentials: true, it still uses"include".Other information (e.g. related issues)
Fixes #5606
The difference is only visible in a browser, since Node.js has no cookie store for
fetch(). The new tests intest/node.js("credentials mode of the fetch() transport") wrap the globalfetch()and check thecredentialsvalue that the transport gives:"same-origin"withwithCredentials: false, and"include"withwithCredentials: true.Test results (Node.js 24.21.0, Windows 11, in
packages/engine.io-clientafternpm run compile):mocha --exit --require test/support/hooks.js --require test/support/env.js test/node.jslib/: 22 passing, 1 failing: the new test "should send same-origin cookies with withCredentials: false" fails with a timeout of 2000 ms (the transport uses"omit")mocha --exit --require test/support/hooks.js test/index.js(the Node.js suite, withouttest/webtransport.mjs): 100 passing, 1 pending; withUSE_FETCH=1: 99 passing, 2 pendingprettier --checkof the changed files: no problemsThis PR was prepared with AI assistance (Claude). The tests named above were run before and after the change, with the results above.
🤖 Generated with Claude Code