irule
Problem this snippet solves:
dsdsdsds
Code :
when RULE_INIT { # This defines how long, in seconds, is the sliding window to count the requests. set static::windowSecs 30 # maxRate requests in windowSecs set static::maxRate 3 # Life timer of the subtable object. Defines how long this object exist in the subtable set static::timeout 300 } when HTTP_REQUEST { # This is the problematic PL/SQL package invoked by web scrapers if { [string tolower [HTTP::uri]] contains "bwckschd.p_disp_detail_sched" } { # Check if there is an entry for the client_addr in the table if { [ table lookup -notouch [IP::client_addr] ] != "" } { # If the value is less than the max rate increment it by one log local0. "Client Throttle: Value present for [IP::client_addr]" if { [ table lookup -notouch [client_addr] ] < $static::maxRate } { log local0. "Client Throttle: Number of requests from client = [ table lookup -notouch [client_addr] ]" table incr -notouch [IP::client_addr] 1 } else { log local0. "Client Throttle: Client has exceeded the number of allowed requests of [ table lookup -notouch [client_addr] ]" # This else statement is invoked when the table key value for the client IP address is more than the max rate. That is, the client has reached the request limit HTTP::respond 200 content {Information Page We are sorry, but the site has received too many requests. Please try again later. } } } else { # If there is no entry for the client_addr create a new table to track number of HTTP_REQUEST. log local0. "Client Throttle: Table created for [IP::client_addr]" table set [IP::client_addr] $static::timeout $static::windowSecs } } else { return } }
Tested this on version:
12.1Published Mar 08, 2018
Version 1.0No CommentsBe the first to comment