Forum Discussion

____177053's avatar
Jul 21, 2017

How to remove the last IP from X-Forwarded-For

If there's multiple IP address in X-Forwarded-For,how to remove the last IP address?

 

  • Hello,

    Given the XFF in general list format, I would do so:
    Incoming: X-Forwarded-For: 10.10.10.10, 10.10.10.20, 10.10.10.30
    Outgoing: X-Forwarded-For: 10.10.10.10, 10.10.10.20
    

    Sintax:

    when HTTP_REQUEST {
        if { [HTTP::header exists X-Forwarded-For] && [HTTP::header X-Forwarded-For] contains "," } {
            set xff [HTTP::header X-Forwarded-For]
            HTTP::header replace X-Forwarded-For [string range $xff 0 [expr {[string last , $xff]-1}]]
        }
    }
    

    Regards.