Skip to content
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: [#1631] Set fetch credentials to same-origin for xhr when withCredentials is false #1632

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

saitonakamura
Copy link

@saitonakamura saitonakamura commented Dec 4, 2024

To more accurately emulate xhr spec behaviour https://xhr.spec.whatwg.org/#the-withcredentials-attribute

It looks like credentials should be set to same-origin when using xhr with withCredentials false, because xhr will only stop sending credentials if the request is not the same origin, and send method of fetch will call getRequestHeaders which performs this kind of check. I might be missing something, some kind of behaviour that will break with same-origin and was working correctly with omit, but I struggle to find it.

I'm not sure if my approach to tests is good enough. I tried to do this via unit test first, but every test there mocks the send implementation (and the send method calls getRequestHeaders) so I decided that I'd rather write an integration test and a unit test will check what kind of credentials option is passed to fetch. So let me know if you have better idea of how to refactor the tests if it's needed

Fixes #1631

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant