Skip to content

fix(eio-client): send same-origin cookies with the fetch() transport - #5607

Open
mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/eio-client-fetch-same-origin-credentials
Open

mark1russell7 wants to merge 1 commit into
socketio:mainfrom
mark1russell7:fix/eio-client-fetch-same-origin-credentials

Conversation

@mark1russell7

@mark1russell7 mark1russell7 commented Nov 13, 2026 •

Copy link
Copy Markdown

The kind of change this PR does introduce

  • a bug fix
  • a new feature
  • an update to the documentation
  • a code change that improves performance
  • other

Current behavior

With withCredentials: false (the default), the Fetch transport calls fetch() with credentials: "omit". This mode drops the cookies also for same-origin requests, and ignores the Set-Cookie headers of the responses. The XHR transport sends the same-origin cookies, so sticky-session cookies (of a load balancer, or of the cookie option of the server) are lost when an application switches to Fetch.

New behavior

The Fetch transport uses credentials: "same-origin" when withCredentials is false, which is the behavior of XMLHttpRequest with withCredentials = false: cookies for same-origin requests, no cookies for cross-origin requests. With withCredentials: 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 in test/node.js ("credentials mode of the fetch() transport") wrap the global fetch() and check the credentials value that the transport gives: "same-origin" with withCredentials: false, and "include" with withCredentials: true.

Test results (Node.js 24.21.0, Windows 11, in packages/engine.io-client after npm run compile):

  • mocha --exit --require test/support/hooks.js --require test/support/env.js test/node.js
    • without the change of lib/: 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")
    • with the change: 23 passing
  • mocha --exit --require test/support/hooks.js test/index.js (the Node.js suite, without test/webtransport.mjs): 100 passing, 1 pending; with USE_FETCH=1: 99 passing, 2 pending
  • prettier --check of the changed files: no problems

This 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

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[engine.io-client] The fetch() transport does not send same-origin cookies when withCredentials is false

1 participant