Help with X-Forwarded-For iRule

We have many (over 500) Public VIP that we need to insert the client IP in the header for security reasons. When i enabled X-Forwarded-For in the HTTP profile the developer informed me they are receiving WAY too many characters in the header and it causes issues on the database. So i figured out those values are being inserted before it reaches our network. So i configured the iRule (below) but its still causing the character limit issue on the database but i did notice 1 thing that caught my eye. Its inserting the VLAN ID after the client address. Has anyone experienced this before or knows how this can be fixed using the iRule?

iRule:

when HTTP_REQUEST {

log local0. “Orig XFF: [HTTP::header values “X-Forwarded-For”]”

HTTP::header remove “X-Forwarded-For”

HTTP::header insert “X-Forwarded-For” [IP::client_addr]

log local0. “New XFF: [HTTP::header value “X-Forwarded-For”]”

}

Value being logged on LTM:

Orig XFF: X.X.X.X (IP removed for security reasons)

New XFF: X.X.X.X%1000 (IP removed for security reasons)

Developwer confinmed they see this in the logs:

X.X.X.X%1000 (IP removed for security reasons)

I would not enable the acceptance of XFF, for it can be faked. You should only trust the IP address that initiated the connection as the client address. As such, you can try the irule below.

when HTTP_REQUEST_RELEASE {
    log local0. "Orig XFF: [HTTP::header values "X-Forwarded-For"]"
    HTTP::header remove "X-Forwarded-For"
    HTTP::header insert "X-Forwarded-For" [getfield [IP::client_addr] % 1],[getfield [IP::local_addr] % 1]
    log local0. "New XFF: [HTTP::header value "X-Forwarded-For"]"
}

.

i still see the %1000 after the IP and now i also see the self ip after the client IP

Orig XFF: X.X.X.X (IP removed for security reasons)

New XFF: X.X.X.X%1000,XX.XXX.XXX.X (IP removed for security reasons)

Are you saying that “New XFF” _added_ “%1000”?

Yeah the iRule example you provided above adds the route domain to the new XFF value (same as my iRule did) but it also inserts the self ip. But i found an iRule that fixed the issue. Now i just need to make sure even if someone tries to spoof the IP i log the correct ip.

Modifying the HTTP X-Forwarded-For header to remove the route domain suffix

Ah I see, mine had the quotes, which I shall remove.

That worked perfectly, i just removed the second “,[getfield [IP::local_addr] % 1]” since i dont want it to log the Self IP.

when HTTP_REQUEST_RELEASE {

log local0. “Orig XFF: [HTTP::header values “X-Forwarded-For”]”

HTTP::header remove “X-Forwarded-For”

HTTP::header insert “X-Forwarded-For” [getfield [IP::client_addr] % 1]

log local0. “New XFF: [HTTP::header value “X-Forwarded-For”]”

}

I spoofed my IP and the iRule removed the spoofed ip and inserted my real public IP.

Thank You for your help.