Hello, I’ve been back and forth over this simple block of code, extracted from our f5 rule. I’m trying to adjust to Cloudflare X-Forwarded-For header for handling source IP address comparison to an internal list of credible internal IP ranges. While I understand that the “X-Forwarded-For” header is not 100% reliable, having this value set will aid debugging in other respects.
When I call this f5 irule with no headers, it is fine, it appears to use the client_addr normally against our whitelist address Data Groups (very simple list of allowed ranges). But when I call it with a header of X-Forwarded-For via Postman it does not respond at all to the client (fails hard). I thought all Tcl variables are Tcl String, but is there something I need to convert extra for headers? -value on the header did not help either.
when HTTP_REQUEST {<br><br><br>if {[HTTP::header exists "X-Forwarded-For"]}{<br> set ip [HTTP::header "X-Forwarded-For"]<br>} else {<br> set ip [IP::client_addr]<br>}<br><br><br>set externalHost 1<br>if {[class match $ip equals Internal_Hosts]}{<br> set externalHost 0<br>}<br><br><br>if {($externalHost == 0)}{<br>HTTP::respond 200 content {<br> externalHost=0<br>}<br>} elseif {($externalHost == 1)}{<br>HTTP::respond 200 content {<br> externalHost=1<br>}<br>} else {<br>HTTP::respond 200 content {<br> externalHost=unknown<br>}<br><br>}