postgrest icon indicating copy to clipboard operation
postgrest copied to clipboard

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

Open steve-chavez opened this issue 1 year ago • 8 comments

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

steve-chavez avatar Feb 02 '24 19:02 steve-chavez

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

wolfgangwalther avatar Feb 07 '24 11:02 wolfgangwalther

@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

  • https://hackage.haskell.org/package/warp-3.4.0/docs/Network-Wai-Handler-Warp.html#v:setHost
  • https://hackage.haskell.org/package/warp-3.4.0/docs/Network-Wai-Handler-Warp.html#t:HostPreference

steve-chavez avatar Feb 07 '24 13:02 steve-chavez

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.

wolfgangwalther avatar Feb 07 '24 13:02 wolfgangwalther

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

laurenceisla avatar Feb 07 '24 20:02 laurenceisla

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

steve-chavez avatar Feb 07 '24 21:02 steve-chavez

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

laurenceisla avatar Feb 07 '24 21:02 laurenceisla

Made a gist with the tests I did:

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

The behavior is the same with Warp only.

laurenceisla avatar Feb 08 '24 01:02 laurenceisla

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

laurenceisla avatar Feb 08 '24 19:02 laurenceisla