fpco / streaming-commons

Common lower-level functions needed by various streaming data libraries
MIT License
36 stars 39 forks source link

HostPreference not binding correctly for `!6` and `*` special values #78

Open laurenceisla opened 6 months ago

laurenceisla commented 6 months ago

We stumbled with this problem via Warp and opened an issue there: https://github.com/yesodweb/wai/issues/976#issue-2125889697. But the problem was with how HostPreference was behaving which is defined in this project.

I'll copy the issue here:

Issue

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 with Warp 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
laurenceisla commented 6 months ago

Here are more detailed results on how the HostPreference is behaving:

https://github.com/yesodweb/wai/issues/976#issuecomment-1937766650