Does anyone know how to get the unchanged IP addre...
# ktor
r
Does anyone know how to get the unchanged IP address of the client? Because in the docs of call.request.origin.remoteAddress It says that it can be easily overridden
s
The exact answer depends on what you need it for and what kind of environment your server is running in, but you can find a comprehensive explanation here: https://adam-p.ca/blog/2022/03/x-forwarded-for/ tl;dr: this is a minefield, so if you can avoid relying on the client IP you should. If you have no other option, you'll need to craft a solution based on the specifics of your own infrastructure.
r
So ktor doesn't provide a way to do it?
s
There is no "it". There are many different headers you might need to inspect and different ways of parsing them depending on what other layers sit between your server and your client.
👆 2
r
I mean like the raw IP without any headers
s
The only way you'll have access to that is if your client is connecting directly to your Ktor server. That's unlikely to be the case in any modern deployment. If there is any other server in between, the IP you see will be the IP of that server instead of your actual client.
r
Ok, so if it's a client from the outside then the real IP will be shown?
s
I'm not sure I understand what you mean by that
r
I mean if it's not a reverse proxy and just a normal client
s
If you genuinely have a client connecting directly to your server with no reverse proxy of any kind in between the two, then yes, you will get the real client IP.
r
Ok, thanks for help