spring-security icon indicating copy to clipboard operation
spring-security copied to clipboard

[Enhancement request] IP of the user making the authentication

Open patpatpat123 opened this issue 1 month ago • 1 comments

Context

Hello,

I would like to reach out with a small question. I did ask the same in Stack Overflow, but the question was closed, as they mentioned this is not an issue, there is no stack trace to paste, etc. Therefore, could you please help me not be a ping pong ball between Stack Overflow and GitHub? If I can get two minutes of your time.

There is a function in Spring Security that provides remote address.

        final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        final WebAuthenticationDetails webAuthenticationDetails = (WebAuthenticationDetails) authentication.getDetails();
        final var remoteadress = webAuthenticationDetails.getRemoteAddress();

I think it is working, as I do get an IP. I was wondering what IP I get?

Let us say the auth server is deployed in the US. I have a first user Alice, who logs in from France Another second user, Bob, logged in from Australia.

From the code above, the remote address is the IP of the user who is authenticating ( I get Alice's and Bob's IPs, one IP from France, another from Australia).

Or the server on which the user is authenticating. (The IP of the US one)

Is there a way to get it otherwise with Spring Security? Thank you

Expected Behavior

I would like to get the IP of the user who is performing the auth.

Current Behavior

Not sure, hence the question

patpatpat123 avatar Dec 10 '25 04:12 patpatpat123

It's the IP of the user who is authenticating, if there's no HTTP proxy involved. It's called "remote address" because from the server's perspective the client side is remote.

If you deploy your application behind a reverse proxy, or the user uses a forward proxy or forges an address behind proxy, the answer may differ. You can check Spring Boot's documentation on this topic:

ziqin avatar Dec 12 '25 17:12 ziqin