Skip to content

remix-express/server throws error on IPv6 host or X-Forwarded-Host #9346

Open
@a47ae

Description

@a47ae

Reproduction

The remix-express/server tries to parse the port number from either the host or the X-Forwarded-Host header remix-express/server.ts#L92. In the case that one of them is an IPv6 address the code incorrectly identifies part of the ip address as port because it splits at colons and IPv6 addresses can contain colons.

I created an example here: https://stackblitz.com/edit/remix-run-remix-edjlfm?file=app%2Froutes%2F_index.tsx
The button fetches the current site but adds a custom X-Forwarded-Host header to emulate a server environment. One should see that the request fails and the server logs an Invalid URL error.

We noticed this error with our remix application behind a reverse proxy which does health checks using the internal IPv6 address.

System Info

stackblitz fork, latest packages

"@remix-run/node": "*",
"@remix-run/react": "*",
"@remix-run/serve": "*"


### Used Package Manager

npm

### Expected Behavior

The express server does work even if host or `X-Forwarded-Host` header is an IPv6 address.

### Actual Behavior

The express server throws an error because an invalid url is constructed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions