nathe
Oct 21, 2011Cirrocumulus
Redirect Based on Content
Hello all. Hope you can help. Not new to f5 but new to writing my own iRules.
Scenario: I want to redirect a user to an error page if a certain line of text is returned in the html body. If a user crafts a certain GET request the returned page may include the following error "Microsoft OLE DB Provider for SQL Server error 'xxxxx'" It may also return the SQL table that was queried. I want to stop this information being relayed to the user. I've tried to come up with an iRule below but it's not working - it's not even being triggered from what I can see (or can't see) in the logs. Am I over-complicating things or have I not understood something? I've tried to use the extensive examples on Devcentral and that's why I've come up with the below code.
Any help greatly appreciated.
Rgds
Nathan
when HTTP_RESPONSE {
Default amount of request payload to collect (in bytes)
set collect_length 2048
Check for a non-existent Content-Length header
if {[HTTP::header Content-Length] eq ""}{
Use default collect length of 2k for POSTs without a Content-Length header
set collect_length $collect_length
} elseif {[HTTP::header Content-Length] == 0}{
Don't try collect a payload if there isn't one
unset collect_length
} elseif {[HTTP::header Content-Length] > $collect_length}{
Use default collect length
set collect_length $collect_length
} else {
Collect the actual payload length
set collect_length [HTTP::header Content-Length]
}
If the POST Content-Length isn't 0, collect (a portion of) the payload
if {[info exists collect_length]}{
Trigger collection of the request payload
HTTP::collect $collect_length
}
}
when HTTP_RESPONSE_DATA {
look for SQL Server Provider Error msgs
if { [HTTP::payload] contains "Microsoft OLE DB Provider for SQL Server error"} {
log local0. "found OLE DB Error in response"
HTTP::redirect http://www.domain.com/error.asp
}
}