PostgREST / postgrest

REST API for any Postgres database
https://postgrest.org
MIT License
22.65k stars 1k forks source link

`server-host=!6` also binds to ipv4 #3202

Open steve-chavez opened 4 months ago

steve-chavez commented 4 months ago

Problem

We document that !6 should only bind to ipv6, however a request using ipv4 succeeds

$ PGRST_SERVER_HOST='!6' postgrest-with-postgresql-16 postgrest-run
$ curl localhost:3000/projects  --ipv4 -I
HTTP/1.1 200 OK

Notes

Using !4 works as expected:

PGRST_SERVER_HOST='!4' postgrest-with-postgresql-15 postgrest-run
$ curl localhost:3000/projects  --ipv6 -I
curl: (7) Failed to connect to localhost port 3000 after 0 ms: Connection refused
wolfgangwalther commented 4 months ago

Did you find out whether this and #3203 are actually bugs on our side or in the lib we are using?

steve-chavez commented 4 months ago

@wolfgangwalther Are you able to reproduce? Not sure if this could be OS-specific.

Did you find out whether this and https://github.com/PostgREST/postgrest/issues/3203 are actually bugs on our side or in the lib we are using?

It must be the lib, we only do this: https://github.com/PostgREST/postgrest/blob/71887e4b78aca74adcdabfc61c2901e7e479878f/src/PostgREST/App.hs#L95

wolfgangwalther commented 4 months ago

Are you able to reproduce? Not sure if this could be OS-specific.

I did not try to. I was just wondering, because ...

It must be the lib, we only do this:

... that's what I remembered.

So if you can reproduce this with plain warp, then it would probably be better to raise this upstream.

laurenceisla commented 4 months ago

So if you can reproduce this with plain warp, then it would probably be better to raise this upstream.

I'm testing the library right now to confirm this. The "funny" thing is that * does not seem to accept ipv6 requests.

$ PGRST_SERVER_HOST='*' postgrest-with-postgresql-16 postgrest-run
$ curl localhost:3000/projects  --ipv6 -I
curl: (7) Failed to connect to localhost port 3000 after 0 ms: Couldn't connect to server
steve-chavez commented 4 months ago

@laurenceisla That looks the same as https://github.com/PostgREST/postgrest/issues/3203

laurenceisla commented 4 months ago

@steve-chavez True, didn't check that.

laurenceisla commented 4 months ago

Made a gist with the tests I did:

https://gist.github.com/laurenceisla/61af763fb028437f24e5a869225eb1f8

The behavior is the same with Warp only.

laurenceisla commented 4 months ago

I submitted the issue upstream here: https://github.com/yesodweb/wai/issues/976