The best VPN 2024

The Best VPS 2024

The Best C# Book

OutSystems how to get the real IP after using Cloudflare?

Spread the love

OutSystems how to get the real IP after using Cloudflare? When we deploy the web project developed by OutSystems to the server and use Cloudflare, if we want to obtain the real IP address of the client, we cannot simply call the GetIP action provided by HTTPRequestHandler. If you do this, you will get is just a Cloudflare proxy address.

OutSystems how to get the real IP after using Cloudflare?
OutSystems how to get the real IP after using Cloudflare?

OutSystems how to get the real IP after using Cloudflare

It is precisely because we use Cloudflare that we cannot get the real IP address by directly calling the GetIP action. Regarding this aspect, there is a discussion about this aspect in the Cloudflare community, we can check it out here.

All HTTP connections to Cloudflare return the visitor IP address in the headers:
X-Forwarded-For header
CF-Connecting-IP header

After we understand the above reasons, the rest is very simple. We only need to call GetRequestHeader to get the corresponding header, so that we can get the real IP address of the client.

OutSystems how to get the real IP after using Cloudflare?
OutSystems how to get the real IP after using Cloudflare?

When using Cloudflare, the IP address your server sees is the IP of the Cloudflare proxy, not the real IP of the client making the request. To get the real client IP in an OutSystems application, you can retrieve it from the HTTP headers set by Cloudflare. Cloudflare typically sends the real IP address in the CF-Connecting-IP header.

Here’s how you can do this in OutSystems:

Steps to Retrieve the Real Client IP in OutSystems:

View Post

  1. Access the Request Header:
  • In OutSystems, you can access the request headers using the GetRequestHeader action from the HTTPRequestHandler module.
  • Use the action to get the value of the CF-Connecting-IP header.
  1. Set Up Logic to Extract IP:
  • Create a server action that calls GetRequestHeader and passes "CF-Connecting-IP" as the header name.
  • The output of this action will be the real IP address of the client.

Example Implementation:

  1. Add a Server Action:
  • Create a new Server Action, e.g., GetClientIP.
  • Inside this action, use the GetRequestHeader action from the HTTPRequestHandler module.
  1. Configure GetRequestHeader:
  • Set the HeaderName input parameter to "CF-Connecting-IP".
  1. Return the IP:
  • The output of GetRequestHeader will be the client’s real IP address. Set this as the output of your GetClientIP action.

Example Code:

HeaderName = "CF-Connecting-IP"
ClientIP = HTTPRequestHandler.GetRequestHeader(HeaderName)

OutSystems how to get the real IP after using Cloudflare?

Additional Consideration:

  • If you have multiple proxies or layers in front of your application, you might need to check other headers like X-Forwarded-For in addition to CF-Connecting-IP.

Debugging:

  • Make sure Cloudflare is configured to send this header.
  • Test your application to ensure the correct IP is being returned, especially if you’re behind multiple proxies.

By following these steps, your OutSystems application will be able to retrieve the real client IP address, even when behind Cloudflare.

Leave a Comment