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

Allow setting host header in fetch call #2369

Closed
paulrutter opened this issue Oct 23, 2023 · 5 comments
Closed

Allow setting host header in fetch call #2369

paulrutter opened this issue Oct 23, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@paulrutter
Copy link

paulrutter commented Oct 23, 2023

This would solve...

See #2322 (comment) and https://nodejs.org/en/blog/vulnerability/october-2023-security-releases#undici---cookie-headers-are-not-cleared-in-cross-domain-redirect-in-undici-fetch-high---cve-2023-45143. In the latest security release, fetch doesn't allow setting the host header anymore.

This leads to problems when the host header is a required header, in case you want to do a request to an external application that requires both an IP address and a host header value (for routing the request to the right context).

A similar bug report here: nodejs/node#50305

The implementation should look like...

A solution could be to have a Node.js CLI flag like --allowHostHeader or more generic --allowHeaders=host, that is handled in undici.

I have also considered...

There is no workaround, except using a userland HTTP library like got (which does not block the host header from being set).

@paulrutter paulrutter added the enhancement New feature or request label Oct 23, 2023
@ronag
Copy link
Member

ronag commented Oct 23, 2023

I think this is probably one of those cases where you shoulnd't be using fetch. Use undici.request instead.

@paulrutter
Copy link
Author

@ronag does that mean that my application then has to add a dependency on undici, and thus not use Node.js fetch?

@ronag
Copy link
Member

ronag commented Oct 23, 2023

@ronag does that mean that my application then has to add a dependency on undici, and thus not use Node.js fetch?

Correct.

@ronag
Copy link
Member

ronag commented Oct 23, 2023

fetch should really just be used for cases where isomorphic code is required, e.g. libraries. It's simply not the right tool for back end development in general.

@paulrutter
Copy link
Author

paulrutter commented Oct 23, 2023

Ok, that makes sense. Will have a go with that approach.

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

2 participants