Forum Discussion
Irule with regex filtering migrate from netscaler
Hi,
On Netscaler migration I come to a rule that could not solve.
On netscaler responder rules there is a drop rule related with this regexp line. I wonder how can i write this on f5 irule.
Netscaler Rule HTTP.REQ.URL.PATH_AND_QUERY.AFTER_REGEX(re/\?/).BEFORE_REGEX(re/:/).REGEX_MATCH(re/(action$|redirect$|redirectAction$)/)
Can anyone help me to write this as F5 irule.
Thanks friends.
5 Replies
- maximillean_953
Nimbostratus
api drop rce when HTTP_REQUEST { if { ([HTTP::query] starts_with "action:") || ([HTTP::query] starts_with "redirect:") || ([HTTP::query] starts_with "redirectAction:") } then { reject } }I try this one but it does not work.
- Vitaliy_Savrans
Nacreous
Hi,
you can try to use this one (log is optional):
when HTTP_REQUEST { if {[HTTP::uri] contains "action" or [HTTP::uri] contains "redirect" or [HTTP::uri] contains "redirectAction"} { log local0. "Query string of URI is [HTTP::uri]" reject } } - maximillean_953
Nimbostratus
No we are not looking for contains. Cause. It can pass first quest with redirect1: but can not be redirect: or redirect: word can pass later of the url.
I wrote a polict with starts_with and all solved for now.
- Kevin_Stewart
Employee
If you break it down like this:
HTTP. REQ. URL. PATH_AND_QUERY. AFTER_REGEX(re/\?/). BEFORE_REGEX(re/:/). REGEX_MATCH(re/(action$|redirect$|redirectAction$)/)And based on this reference:
I think what it's basically saying is this:
- Start with the full HTTP request URI (path, query string, and all)
- From that, return the string that is after the question mark (?)
- From that, return the string that is before the colon (:)
- And if the resulting string ends with ($) "action", or "redirect", or "redirectAction", then drop the request.
So then the resulting iRule might look like this:
when HTTP_REQUEST { if { [regexp -all {(action|redirectaction|redirect)} [string tolower [findstr [HTTP::uri] "?" 1 ":"]]] > 0 } { drop } }Or, if you wanted to avoid the regex:
when HTTP_REQUEST { if { ( [string tolower [findstr [HTTP::uri] "?" 1 ":"]] ends_with "action" ) or ( [string tolower [findstr [HTTP::uri] "?" 1 ":"]] ends_with "redirect" ) or ( [string tolower [findstr [HTTP::uri] "?" 1 ":"]] ends_with "redirectaction" ) } { drop } }Or:
when HTTP_REQUEST { switch -glob [string tolower [findstr [HTTP::uri] "?" 1 ":"]] { "*action" - "*redirect" - "*redirectaction" { drop } default { return } } } - maximillean_953
Nimbostratus
Thanks alot. Perfectly worked. I solved it with writing policy rather then i rule. Now i am going to remove policy i wrote and apply this irule.
be well and take care Kevin.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* 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
