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

Should fetch pass cookies when following redirects? #1640

Open
dsine-de opened this issue Sep 7, 2022 · 2 comments
Open

Should fetch pass cookies when following redirects? #1640

dsine-de opened this issue Sep 7, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@dsine-de
Copy link

dsine-de commented Sep 7, 2022

Software like Postman (if not disabling the cookie jar in the settings) and browser redirects save cookies when they hit a redirect which has a set-cookie header and set them on requests following that redirect by adding a cookie header.

Should Node.js fetch do this too?

When I request the http://localhost:8080/redirect from this code with Postman, it logs the cookie header and in the Postman console you see the cookie was added to the following request. The native fetch that happens in the code doesn't pass the cookie to the /redirect_to url.

import express from 'express';

const app = express();

app.get('/redirect', (req, res, next) => {
	res.cookie('test', 'value');
	res.redirect('/redirect_to');
});

app.get('/redirect_to', (req, res, next) => {
	console.log(`Cookie: ${req.get('cookie')}`);
	res.status(200).end();
});

app.listen(8080, async () => {
	try {
		await fetch('http://localhost:8080/redirect');

		await fetch('http://localhost:8080/redirect', {
			credentials: 'include'
		});
	} catch (err) {
		console.error(err);
	}
});

Here is the minimal reproduction repository:
https://github.com/dsine-de/fetch-redirect-cookies

@dsine-de dsine-de added the enhancement New feature or request label Sep 7, 2022
@mcollina
Copy link
Member

mcollina commented Sep 7, 2022

I don't think we handle cookies right now.
@KhafraDev @ronag wdyt?

@KhafraDev
Copy link
Member

We likely need to wait for something along the lines of whatwg/fetch#1384. Maybe it'd be better as a wintercg issue as this is more pertinent to non-browser environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants