Filtering a list of URLs

Hello Everyone,

To start off, I’d like to mention that I am pretty new at this F5 business (been reading on it for about 2wks).

I am trying to find the best way to filter a list of URLs. Below is the current iRule that we are using, but as you can imagine as the need for additional URLs to be added to the iRule arises, it will be harder to keep track of them. So as a different solution, I would like to be able to insert a new URL into a list instead of having to create an “elseif” statement everytime.

Any help will be greatly appreciated :slight_smile:

when HTTP_REQUEST {

where member is the parameter name

set member_param_1 “/mailSchedulingServices/mailSchedulingService.svc”

set member_param_2 “/cardPayMatrixSvc/cardPayMatrixSvc.svc”

set response_data “Unauthorized request”

if {[string match $member_param_1 [HTTP::path]]}{

Do nothing

}

elseif {[string match $member_param_2 [HTTP::path]]} {

Do nothing

} else {

log local0. “Compare response with $member_param”

HTTP::respond 200 content $response_data

}

}

Hi,

Welcome to the forums. If you want to create a whitelist of allowed URIs, you could add them to a string datagroup (in the GUI under Local Traffic >> iRules >> Datagroup tab >> Create. You could then use the class command to look up the current path against the datagroup. If the requested path isn’t in the datagroup, you could send a 200 response with content.

Here is the datagroup as it would appear in the bigip.conf:

class whitelist_paths_class {
   {
      "/cardPayMatrixSvc/cardPayMatrixSvc.svc"
      "/mailSchedulingServices/mailSchedulingService.svc"
   }
}

And here is an example iRule to do the lookup:

when RULE_INIT {

   set static::block_html {Access denied!}
}
when HTTP_REQUEST {

   if { not [class match [HTTP::path] equals whitelist_paths_class]}{

      HTTP::respond 200 content $static::block_html
   }
}

Aaron

Thank you Aaron!

Is there a way to do it without using datagroups?

The reason I ask is because I was given this assignment as a “good starting point” to understand iRules. The person that assigned this task to me asked me to see if there is a way to do it using the “array” syntax.

When I tried your suggestion I get an error saying:

line 5: [undefined procedure: class] [class match [HTTP::path]

When I tried your suggestion I get an error saying:

line 5: [undefined procedure: class] [class match [HTTP::path]

When I tried your suggestion I get an error saying:

line 5: [undefined procedure: class] [class match [HTTP::path]

If the class command doesn’t exist, you’re running v9. You can use matchclass instead:

when HTTP_REQUEST {

   if { not [matchclass [HTTP::path] equals whitelist_paths_class]}{

      HTTP::respond 200 content {Access denied!}
   }
}

You could do this in an array, but it would be inefficient compared with a datagroup.

Aaron

Ok. I really appreciate all the help.

One last thing..could you please explain what is happening in the line that says “if { not [matchclass [HTTP::path] equals whitelist_paths_class]}{”

matchclass looks up to see if the HTTP::path value exactly matches any entry in the datagroup named “whitelist_paths_class”. Then not negates that. So if the requested path isn’t in the datagroup, a 200 response is sent back to the client with the HTML content.

You can get more info on the matchclass wiki page:

http://devcentral.f5.com/wiki/default.aspx/iRules/matchclass

Aaron

Sweet thanks! :slight_smile:

I edited your suggestion and rewrote it like this so that I don’t use Run_init …when i use this it looks like i am no longer to connect to that URL through the browser

when HTTP_REQUEST {

set response_data “Unauthorized request”

if { not [matchclass [HTTP::path] equals Dev_URL_List]}{

}

HTTP::respond 200 content $response_data

}

}

You need to move the HTTP::respond under the if statement otherwise it will trigger on every HTTP request.

Aaron

What he means is:

when HTTP_REQUEST { 
  set response_data "Unauthorized request" 
  if { not [matchclass [HTTP::path] equals Dev_URL_List]} { 
    HTTP::respond 200 content $response_data 
  } 
}

You could also do without the “$response_data” variable if you’re just sending a static string like that, fyi.

Colin

I copied it just like you have it and I get a message on the browser saying “Internet Explorer cannot display webpage”

So I have a Data Group titled “Dev_URL_List” with a list of URLs in it. Then I have the following iRule and I am not able to connect to that site anymore

when HTTP_REQUEST {

set response_data “Unauthorized request”

if { not [matchclass [HTTP::path] equals Dev_URL_List]} {

HTTP::respond 200 content $response_data

}

}

If you get a page cannot be displayed error in the GUI it generally indicates the client has received a TCP reset. Can you check /var/log/ltm to see if there is a runtime TCL error from the iRule? If it’s something about the class not being found, can you post the following:

b class Dev_URL_List list

b rule RULE_NAME list

Aaron

There’s likely an error somewhere. Could you paste in what your /var/log/ltm log says when you try to request that site with the iRule in place?

The iRule’s syntax looks okay to me, so I’m guessing that something just isn’t lining up, whether it be a name or the contents of the Data Group, etc.

Colin

Yeah…what he said. :wink:

Colin

I checked the logs and this is what it says:

Status code 01220001

TCL error: Rule junk HTTP_REQUEST - Invalid matchclass operands - no class or list type found, lhs: string, rhs: Dev_URL_List line 2 invoked from within matchclass [HTTP::path] equals Dev_URL_List

Dev_URL_List (String Type)

/cardPayMatrixSvc/cardPayMatrixSvc.svc

/mailSchedulingServices/mailSchedulingService.svc

the name of the iRule is “junk” :slight_smile:

Oh…what version are you running?

You might want to try updating the iRule slightly.

when HTTP_REQUEST { 
  set response_data "Unauthorized request" 
  if { not [matchclass [HTTP::path] equals $::Dev_URL_List]} { 
    HTTP::respond 200 content $response_data 
  } 
}

Colin