X-Forwarded-For Header Insert

X-Forwarded-For Header Insert

book

Article ID: CTX218061

calendar_today

Updated On:

Description

Use Case

X-Forwarded-For header can be used to pass the Client IP information to the backend server.

When HTTP request contains X-Forwarded-For header, the values will be replaced with single client IP address.
If there is no X-Forwarded-For header, it will be added and assigned with the client IP address.

F5 iRules

when HTTP_REQUEST {
 if {[HTTP::header exists X-Forwarded-For]}{
 HTTP::header replace X-Forwarded-For "[HTTP::header X-Forwarded-For], [IP::
client_addr]"
 } else {
 HTTP::header insert X-Forwarded-For [IP::client_addr]
 }
}

NetScaler Solution

add rewrite action xforward_act replace "HTTP.REQ.HEADER(\"X-Forwarded-For\")" CLIENT.IP.SRC
add rewrite policy xforward_check_pol "HTTP.REQ.HEADER(\"X-Forwarded-For\").EXISTS" xforward_act

Bind the above policy to Global or vServer level bind point.

add rewrite action xforward_add insert_http_header X-Forwarded-For CLIENT.IP.SRC
add rewrite policy xforward_add_pol "HTTP.REQ.HEADER(\"X-Forwarded-For\").EXISTS.NOT" xforward_add

Bind the above policy to Global or vServer level bind point.

Issue/Introduction

X-Forwarded-For Header Insert