yesodweb / wai

Haskell Web Application Interface
MIT License
834 stars 263 forks source link

Warp host preference not binding correctly for `!6` and `*` special values #976

Closed laurenceisla closed 7 months ago

laurenceisla commented 9 months ago

System info

OS: NixOS 23.05 Cabal: 3.10.1.0 GHC: 9.2.8 Dependencies:

base ^>=4.16.4.0,
warp >= 3.4.0,
wai  >= 3.2.1 && < 3.3
http-types >= 0.12.3 && < 0.13

Uname:

$ command -v uname && uname -a # Kernel version
/nix/store/l9mg93sgx50y88p5rr6x1vib6j1rjsds-coreutils-9.1/bin/uname
Linux nixos 6.5.7 #1-NixOS SMP PREEMPT_DYNAMIC Tue Oct 10 20:03:06 UTC 2023 x86_64 GNU/Linux

Issue

In warp, when setting a !6 host preference it does not seem to bind to ipv6 exclusively, because ipv4 requests do not fail. Also, when setting the preference to *, ipv6 requests fail when they shouldn't. I included a simple example in this Gist: https://gist.github.com/laurenceisla/61af763fb028437f24e5a869225eb1f8

These are the results I got:

It allows both ipv4 and ipv6 requests when setHost !6

$ curl "http://localhost:3000" --ipv4 -I
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Thu, 08 Feb 2024 01:19:54 GMT
Server: Warp/3.4.0
Content-Type: text/plain

It does not allow ipv6 requests when setHost *

$ curl "http://localhost:3000" --ipv6 -I
curl: (7) Failed to connect to localhost port 3000 after 0 ms: Couldn't connect to server

setHost !4 working as expected

$ curl "http://localhost:3000" --ipv6 -I
curl: (7) Failed to connect to localhost port 3000 after 0 ms: Couldn't connect to server
wolfgangwalther commented 9 months ago

I did a bit of testing, and here are my results:

The docs are not entirely clear to me about what is correct for *4 and *6 - but surely the results are inconsistent here.

wolfgangwalther commented 9 months ago

It seems like the HostPreference setting is from https://github.com/fpco/streaming-commons, though. Should we report this there?

kazu-yamamoto commented 9 months ago

Yes. Please provide this to streaming-commons.

kazu-yamamoto commented 7 months ago

Closing in favor of the upstream issue.