Forum Discussion

EddieJK_26590's avatar
EddieJK_26590
Icon for Nimbostratus rankNimbostratus
May 01, 2017

How do you block empty user-agents?

Hi,

 

I want to create an iRule to block empty user-agents from hitting our web site instead of letting IIS do it. I've read several posts and came up with this one. Is this ok?

 

 

Thanks

 

Eddie

 

7 Replies

  • This is the iRule:

     

    if { [HTTP::header exists "User-Agent"]} { if { [HTTP::header "User-Agent"] equals "" } { reject } }

     

  • iRule looks to be good. Try it out. Make sure to add "when HTTP_REQUEST" as the event.

     

  • I am getting the following error:

     

    The requested object name (user agents) is invalid

     

  • I changed it to the following below, but still have the same error.

     

    when HTTP_RESPONSE { if { [HTTP::header exists User-Agent]} { if { [HTTP::header User-Agent] equals "" } { reject } }

     

  • If you need to block incoming request from client, you need to use HTTP_REQUEST

     

  • I was not able to test these, but either should get you the results you are looking for:

    when HTTP_REQUEST { 
    if {[class match [HTTP::header "User-Agent"] equals ""]} {
      reject  
    }}
    

    OR

    when HTTP_REQUEST {
    if { [HTTP::header exists User-Agent]} { if { [HTTP::header User-Agent] equals "" } {
        reject
    }}}
    

    Good Luck!