Forum Discussion
mtobkes_64700
Nimbostratus
Mar 11, 2010Can iRule Reject Requests Based on 'True-Client-IP'
Can someone please tell me if the LTM v9.4.7 can take action on requests, based on the HTTP header value for 'True-Client-IP'?
We will be 'Akamaizing' parts of our website and will no longer see the clients address in the IP header.
Akamai will insert the client's IP in the HTTP header 'True-Client-IP'. We will now need the ability to block requests based on this layer 7 information.
Here is an iRule I found posted:
when HTTP_REQUEST {
if { [HTTP::header exists "True-Client-IP"] } {
set xff [HTTP::header "True-Client-IP"]
xff may be in format of addr1,addr2,addr3
set addrs [split $xff ","]
foreach addr $addrs {
if { [matchclass $::banned_addr_list equals $addr] } {
reject
}
}
}
}
Will this iRule accomplish what I am trying to do?
Thanks,
-MT
- Hamish
Cirrocumulus
Without checking your syntax, the logic looks OK (It'd have done it slightly differently, but that's just optimisation). - hoolio
Cirrostratus
You might also check to see if Akamai strips out any previously existing True-Client-IP headers before inserting it's own. You could test this to see. If they don't then you could check to see whether Akamai's header is always inserted last. In that case, you should be fine using hte iRule as HTTP::header retrieves the value for the last named header.when HTTP_REQUEST { if { [HTTP::header "True-Client-IP"] ne ""} { header may be in format of addr1,addr2,addr3 foreach addr [split [HTTP::header "True-Client-IP"] ","] { if { [matchclass banned_addr_list equals $addr] } { HTTP::respond 403 } } } }
- mtobkes_64700
Nimbostratus
Thanks! - hoolio
Cirrostratus
That looks good. For 9.4.4+ you can remove the $:: prefix from the datagroup to make the iRule CMP compatible (assuming you have a CMP compatible platform Click here). - mtobkes_64700
Nimbostratus
Sorry for the confusion. What I meant to say was that I'd like to send a 403 or 404 if the 'True-Client-IP' matches my data list 'banned_addr_list' (my iRule shows a 404 response). This was suggested by Hamish in his previous reply: - hoolio
Cirrostratus
RFC2616 states that you should send a 403 for this case. But what you actually use is up to you. 404 could be appropriate. Just make sure to set cache control headers if you use a 404 to prevent proxies from caching the response.
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects