Ktor: Get client IP behind proxy

Created on 7 Mar 2018  路  7Comments  路  Source: ktorio/ktor

Does ktor offer a way to obtain client IP when behind proxy?
Thanks

Most helpful comment

A service which is _not_ behind a proxy shouldn't use this feature, because it can be spoofed by a malicious client.

All 7 comments

Yes, call.request.origin gives connection properties of the original caller (to proxy) if proxy provides proper headers and XForwardedHeadersSupport is installed.

While writting the feature page about XForwardedHeadersSupport, I have added this to the FAQ:
http://ktor.io/servers/faq.html#proxy-ip

Just added this page to the documentation:

http://ktor.io/servers/requests.html#properties

You are interested into: call.request.origin.remoteHost

Thanks for fast response 馃憤

I think this has a bug: I've checked that mod_proxy_http adds the 'X-Forwarded-For' header, but call.request.origin.remoteHost contains '0:0:0:0:0:0:0:1' instead of the ip in the 'X-Forwarded-For' header

Ran on 1.0.1, upgraded to 1.1.1, but it didn't help

Ah, thought this was default behaviour and I missed that I should call
install(XForwardedHeaderSupport)

A service which is _not_ behind a proxy shouldn't use this feature, because it can be spoofed by a malicious client.

Was this page helpful?
0 / 5 - 0 ratings