Skip to content

Case-sensitive host header lookup in fetch redirect breaks cross-origin requests with custom headers #41766

Description

@rahulrao85

Description

In fetch.ts (line 464), the redirect host header update uses a case-sensitive key lookup:

if (headers['host'])
    headers['host'] = locationURL.host;

This is inconsistent with the rest of the file, where every other header operation uses case-insensitive lookup:

  • setHeader() (line 935): uses Object.entries().find(pair => pair[0].toLowerCase() === name.toLowerCase())
  • getHeader() (line 943): same
  • removeHeader() (line 948): same

If extraHTTPHeaders or any other header source sets 'Host' (capital H), headers['host'] (lowercase) returns undefined, and the host header is never updated for the redirect target. The redirect request retains the original host header unmodified.

Impact

  • Redirects from https://example.com/page to https://api.example.com/data will send Host: example.com instead of Host: api.example.com
  • This causes connection failures or incorrect routing for any cross-origin redirect where the Host header was set with non-lowercase casing
  • Particularly impacts users who set custom extraHTTPHeaders via browserContext.setExtraHTTPHeaders()
  • The fix is a one-line change

Suggested Fix

const hostKey = Object.keys(headers).find(k => k.toLowerCase() === 'host');
if (hostKey)
    headers[hostKey] = locationURL.host;

This matches the pattern used by setHeader, getHeader, and removeHeader in the same file.

Activity

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions