Skip to content

X-Forwarded-For overwrite or remove mode in ALB

1

Hi! I am trying to pass the real client IP address of the request arrived at the ALB, so I can retrieve it from my web server in a header. Initially, I thought that the "remove" mode in the attribute that manages the behavior of X-Forwarded-For in the ALB configuration would remove any existing X-Forwarded-For header but still append the X-Forwarded-For header with the original request IP address that reaches the ALB. However, based on my tests, that is not the case, and the actual behavior—opposed to logic—is that the header gets removed and is not passed to the web server (although curiously, the rest of the X-Forwarded-* headers are still passed). This behavior is frankly frustrating. The only way I can pass the client’s real IP to the web server is through the "append" mode, but this introduces the risk of the original source injecting a malicious header, with a fake IP, etc.

For now, the only workaround I have come up with is blocking all requests arriving at the ALB with an X-Forwarded-For header using a WAF blocking rule, but I’m concerned that this might cause issues in some scenarios.

I’d like to know if the AWS ALB team has any plan to modify the behavior of the "remove" mode so the existing header would be removed but it still would be appended with the client’s real IP.

I understand that another workaround would be using CloudFront and Lambda@Edge, injecting a header with a custom name, but frankly, that feels like using a sledgehammer to crack a nut, unnecessarily complicating the architecture.

Alternatively, it would be great to be able to specify a custom header name in the ALB to capture the client’s real IP, allowing us to handle it on the web server with confidence that it’s the original IP that the request reached the ALB with.

Thanks in advance.

2 Answers
0

Hello, Swasti,

Thank you very much for your prompt response. We are deploying Apereo CAS behind the ALB. This application is based on Spring Boot and uses an embedded Tomcat server. As far as I know, there's no way to retrieve the last IP in the X-Forwarded-For header through configuration properties alone. It seems I would need to write a Java class to modify the RemoteIpValve in the embedded Tomcat. For now, I'll stick with the WAF rule that blocks requests containing the X-Forwarded-For header when they reach the ALB.

Best regards, Oscar.

answered 2 years ago

  • yeah there is no custom made solution for this. You will have to write a custom code on the targets to start with. For now yes you can stick with WAF rules to block X-forwarded for headers. Thats the easiest way of blocking certain requests.

0

Hello,

I understand you have a usecase where you would like to remove X-forwarded-for header coming from the client and just add a new X-forwarded-for header with the actual Client IP that has sent the request.

At this moment, if you have Value as "Remove" for xff header processing mode, then ALB will remove the X-forwarded-for header all together and send the request to the target.

For now you can only use "Append" Value for xff header processing mode and the last IP address in that header that you will receive will be the Client IP, that has sent the request. You will need to create some sort of logic in your web application to get that "Last appended IP" and then decide if the request should be served or not by your servers, or whatever you want to do with the Client IP.

As of now I dont see any feature to change the behavior of these modes from AWS side.

AWS

answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.