Skip to content

Allow setting host header in fetch call #2369

Closed

Description

@paulrutter

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).

Activity

  1. added
    enhancement
    on Oct 23, 2023
  2. ronag commented on Oct 23, 2023

    @ronag
    Member

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

  3. paulrutter commented on Oct 23, 2023

    @paulrutter
    Author

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

  4. ronag commented on Oct 23, 2023

    @ronag
    Member

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

    Correct.

  5. ronag commented on Oct 23, 2023

    @ronag
    Member

    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.

  6. paulrutter commented on Oct 23, 2023

    @paulrutter
    Author

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

  7. MattyBalaam commented on Oct 1, 2024

    @MattyBalaam

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

    I am in a sticky situation where I need to set the Host header but I also need to return a fetch Response object. Does Undici provide a method of converting the undici.request response to a fetch Response?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions