Forum Discussion
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
}
}
- nitassEmployeeis response encoded or does it span multiple packet?
[root@iris:Active] config b virtual bar list virtual bar { snat automap pool foo destination 172.28.17.33:http ip protocol tcp rules myrule profiles { http {} tcp {} } } [root@iris:Active] config b rule myrule list rule myrule { when HTTP_RESPONSE { set collect_length 2048 if {[HTTP::header Content-Length] eq ""}{ set collect_length $collect_length } elseif {[HTTP::header Content-Length] == 0}{ unset collect_length } elseif {[HTTP::header Content-Length] > $collect_length}{ set collect_length $collect_length } else { set collect_length [HTTP::header Content-Length] } if {[info exists collect_length]}{ HTTP::collect $collect_length } } when HTTP_RESPONSE_DATA { 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 } } } [root@iris:Active] config curl -i http://10.10.70.110/foo.html HTTP/1.1 200 OK Date: Fri, 21 Oct 2011 06:27:51 GMT Server: Apache/2.0.59 (rPath) Last-Modified: Fri, 21 Oct 2011 06:24:47 GMT ETag: "66a9-80-213129c0" Accept-Ranges: bytes Content-Length: 128 Vary: Accept-Encoding Set-Cookie: testcookie=helloworld Content-Type: text/html; charset=UTF-8 WELCOME!!!! This's 10.10.70.110. Microsoft OLE DB Provider for SQL Server error [root@iris:Active] config curl -i http://172.28.17.33/foo.html HTTP/1.0 302 Found Location: http://www.domain.com/error.asp Server: BigIP Connection: Keep-Alive Content-Length: 0
- natheCirrocumulusNitass
- nitassEmployeeyes, can you try to force server to http 1.0?
- natheCirrocumulusThanks Nitass
- nitassEmployeeperfect! thanks for update.
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