F5 AWAF geolocation enforcement feature enables administrators to allow or block incoming traffic based on geographic location of the client. The source IP address of a client can be determined even if it is behind a proxy by using X-Forwarded-For (XFF) header.

In this lesson, we will demonstrate how to configure and effectively use this feature.

X-Forwarded-For and Geolocation Enforcement

what is HTTP X-Forwarded-For?

Before we begin discussing Geolocation enforcement, it’s important to understand the HTTP X-Forwarded-For header, which we’ll be using in this demonstration.

When a client makes a request to a server through a proxy, the client’s actual IP address is lost because the source IP address is changed to that of the proxy. The X-Forwarded-For (XFF) header is an HTTP header that the proxy may add, including the original IP address of the client. This header enables the server to identify the true origin of the request despite it passing through one or more proxies.

what is HTTP X-Forwarded-For Header
what is HTTP X-Forwarded-For Header

With the X-Forwarded-For (XFF) HTTP header, F5 AWAF can accurately detect the real IP address of the client, even when the client is behind a proxy. This capability enables F5 AWAF to effectively block traffic based on geolocation information.

Preparing the security policy

To demonstrate F5 AWAF geolocation enforcement, we will use the policy created in previous lessons. This policy is based on a comprehensive security template and is assigned to the “hack-it-yourself” web application.

security policy assigned to hack-it-yourself web application
security policy assigned to hack-it-yourself web application
security policy based on comprehensive security template
security policy based on comprehensive security template

We will also enable “learn,” “alarm,” and “block” for all violations related to “IP addresses and Geolocations” in the “Learning and Blocking Settings“. Specifically, we will focus on the violation “Access from disallowed Geolocation,” which is the main topic of this demonstration.

enable Geolocation violations in learning and blocking setting
enable Geolocation violations in learning and blocking setting

Simulate HTTP request with XFF header using Postman

To simulate sending traffic through a proxy to the web application using the X-Forwarded-For (XFF) header, we’ll use the Postman application. In Postman:

  • Set the request method to “GET.”

  • Enter the URL as “http://auction.f5demo.com/“.

  • Manually add the client’s IP address to the X-Forwarded-For header.

  • Keep all other parameters unchanged.

This configuration enables us to replicate traffic passing through a proxy with the specified client IP address effectively.

Generate an HTTP request with XFF header with the IP address of Zimbabwe via Postman
Generate an HTTP request with XFF header with the IP address of Zimbabwe via Postman

I chose the IP address “169.239.24.10” which is associated with Zimbabwe. I selected Zimbabwe because it was the last country listed in the F5 AWAF geolocation database. I found this sample IP address by searching over the internet.

Zimbabwe IP address ranges
Zimbabwe IP address ranges

To ensure that this IP address is correctly associated with Zimbabwe in the F5 AWAF geolocation database, we can use the “geoip_lookup command to find the geolocation of the IP address. This command will confirm the geographic location details as stored in the database.

[root@awaf:avrd DOWN:Standalone] config # geoip_lookup 102.128.76.0
Will attempt to lookup ip '102.128.76.0'
No database specified.
opening database in /usr/share/GeoIP/v2/F5GeoIP.dat
size of geoip database = 24330336, segments = 9734200, version = Copyright (c) F5 Networks Inc, All Rights Reserved GEOIP2 v1, 20230501
geoip_seek = 00f30002
geoip record ip = 102.128.76.0
country_code = ZW
country_name = Zimbabwe
region_name = Harare
continent_code = AF
Scope = 22
[root@awaf:avrd DOWN:Standalone] config #

Before enabling geolocation enforcement, we will use Postman to connect to the web application and verify that this IP address is currently allowed to access the web application.

If we check the result of the connection in the event log, we will see that the access is successful and permitted. However, we will also notice that the geolocation and source IP address are not updated via the XFF HTTP header. This is because we have not yet configured the system to trust the XFF header.

by default XFF Zimbabwe IP address are not recorded as source IP address in application event log
by default XFF Zimbabwe IP address are not recorded as source IP address in application event log

However, if we examine the details of the HTTP request, we can see that the XFF header with the Zimbabwe IP address is present in the HTTP header. Despite this, the source IP address and geolocation are not updated in the event log because the XFF header has not been configured as a trusted source.

XFF header in HTTP request in application event log
XFF header in HTTP request in application event log

Trust XFF header and configure geolocation enforcement

Now, we will configure the security policy to trust the XFF header and enforce geolocation restrictions.

  1. In the security policy under “General Settings,” enable the option to “Trust XFF Header“.

  2. Navigate to “Geolocation Enforcement” and add the last country on the list, “Zimbabwe,” to the “Disallow Access” list.

These changes will ensure that traffic from Zimbabwe is blocked based on the trusted XFF header.

trust XFF header and enable geolocation enforcement in F5 AWAF security policy
trust XFF header and enable geolocation enforcement in F5 AWAF security policy

We will again attempt to access the web application using Postman, with the XFF header set to an IP address from Zimbabwe. This time, the result shows that access is blocked, demonstrating that the geolocation enforcement is working as configured.

Generate HTTP request with XFF header with Zimbabwe IP address after geolocation enforcement is enabled
Generate HTTP request with XFF header with Zimbabwe IP address after geolocation enforcement is enabled

If we check the event log, we will notice that the traffic is blocked and that the values for Geolocation and the source IP address are updated using the XFF header. This outcome is a direct result of configuring the security policy to trust the XFF header.

XFF IP address is recorded as source IP address in application event log after we trust XFF header
XFF IP address is recorded as source IP address in application event log after we trust XFF header
Back to: F5 BIG-IP AWAF (formerly ASM) > F5 AWAF Security Policy

Leave a Reply

Your email address will not be published. Required fields are marked *


Post comment