Forum Discussion
Bruno_Esteves_2
Nimbostratus
Dec 04, 2015iRule - URI/Referer Rate limit per minute
Dears, We have a customer which is getting some troubles with access coming from an specific referer/uri. These access are overloading the application, causing a lot of troubles to the business. ...
Yann_Desmarest
Cirrus
Jun 01, 2016Hi,
Here a working irule (inspired by http request throttle irule) :
when RULE_INIT {
set static::maxReqs 3;
set static::timeout 60;
}
when HTTP_REQUEST {
if { [HTTP::header exists "X-Forwarded-For"] } {
set client_IP_addr [getfield [lindex [HTTP::header values X-Forwarded-For] 0] "," 1]
} else {
set client_IP_addr [IP::client_addr]
}
if { ([HTTP::method] eq "GET") and ([class match [string tolower [HTTP::uri]] ends_with URI_LIST_TO_LIMIT] ) } {
whitelist
if { [class match [IP::client_addr] equals ips_whitelist] }{
return
}
set getcount [table lookup -notouch "$client_IP_addr:[HTTP::uri]"]
if { $getcount equals "" } {
table set "$client_IP_addr:[HTTP::uri]" "1" $static::timeout $static::timeout
} else {
if { $getcount < $static::maxReqs } {
table incr -notouch "$client_IP_addr:[HTTP::uri]"
} else {
reject
}
}
}
}
- Bruno_Esteves_2Apr 12, 2017
Nimbostratus
Dears,
I'm trying to include a sliding window of time to counting requests. (e.g. if we have 8 req in 60 sec, block for 600 sec.)
So, I did change ($static::timeout $static::timeout) to ($static::timeout $static::winsec) and include this variable (set static::winsec 60). But, didn't work. Have I missed something here ?
Here a working iRule that in using:
when HTTP_REQUEST { if { [HTTP::uri] ends_with "/URI" and [HTTP::method] eq "POST"}{ set static::maxRate 8 set static::timeout 600 set client_IP_addr [IP::client_addr] set getcount [table lookup -notouch "$client_IP_addr:[HTTP::uri]"] if { $getcount equals "" } { table set "$client_IP_addr:[HTTP::uri]" "1" $static::timeout $static::timeout } else { if { $getcount < $static::maxRate } { table incr -notouch "$client_IP_addr:[HTTP::uri]" } else { log -noname local0. "REQUEST Rejected: current requestCount for $client_IP_addr" reject } } } }Cheers, Bruno
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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