# iRule to block http content

**URL:** <https://community.f5.com/t/irule-to-block-http-content/21244>\
**Category:** Technical Forums\
**Tags:** irules, security, ltm, application-delivery\
**Created:** [May 18, 2016, 6:55pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244 "2016-05-18T18:55:55Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mustafa\_Hashmi](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Mustafa\_Hashmi](https://community.f5.com/u/Mustafa_Hashmi)\
**Post date:** [May 18, 2016, 6:55pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/1 "2016-05-18T18:55:55Z")

</div>

Hello all,

I am looking for a simple iRule to inspect HTTP content that is sent back via POST from a particular user and drop if the HTTP content contains

id=sa\_sabre&event=sa\_exchangeSrvr\_state

or

id=sa\_sabre&event=sa\_sip\_state.

Thank you

---

<div class="post-metadata">

**Author:** ![stan\_piron](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@stan\_piron](https://community.f5.com/u/stan_piron)\
**Post date:** [May 18, 2016, 7:04pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/2 "2016-05-18T19:04:04Z")

</div>

try this irule:

```tcl
when HTTP_REQUEST {
    if {([URI::query [HTTP::uri] id] equals "sa_sabre") && (([URI::query [HTTP::uri] event] equals "sa_exchangeSrvr_state") || ([URI::query [HTTP::uri] event] equals "sa_sip_state"))} {
        drop
    }
}

```

---

<div class="post-metadata">

**Author:** ![stan\_piron](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@stan\_piron](https://community.f5.com/u/stan_piron)\
**Post date:** [May 18, 2016, 7:35pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/3 "2016-05-18T19:35:57Z")

</div>

This irule do the same for POST method:

```tcl
when HTTP_REQUEST {
   if { [HTTP::method] eq "POST" } {
       Trigger the collection for up to 1MB of data
      if { [HTTP::header Content-Length] ne "" and [HTTP::header value Content-Length] <= 1048576 } {
         set content_length [HTTP::header value Content-Length]
      } else {
         set content_length 1048576
      }
       Check if $content-length is not set to 0
      if { $content_length > 0 } {
         HTTP::collect $content_length
      }
   }
}
when HTTP_REQUEST_DATA {
    Do stuff with the payload
   set payload "?[HTTP::payload]"
   if {([URI::query $payload id] equals "sa_sabre") && (([URI::query $payload event] equals "sa_exchangeSrvr_state") || ([URI::query $payload event] equals "sa_sip_state"))} {
        drop
    }
}

```

---

<div class="post-metadata">

**Author:** ![Yann\_Desmarest\_1](https://avatars.discourse-cdn.com/v4/letter/y/65b543/32.png) [@Yann\_Desmarest\_1](https://community.f5.com/u/Yann_Desmarest_1)\
**Post date:** [May 23, 2016, 6:02pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/4 "2016-05-23T18:02:58Z")

</div>

Hi,

There is some encoding errors in the above irule, try this one instead, it’s the same with some fixed encoding chars :

```tcl
when HTTP_REQUEST {
   if { [HTTP::method] eq "POST" } {
       Trigger the collection for up to 1MB of data
      if { [HTTP::header Content-Length] ne "" and [HTTP::header value Content-Length] >= 1048576 } {
         set content_length [HTTP::header value Content-Length]
      } else {
         set content_length 1048576
      }
       Check if $content-length is not set to 0
      if { $content_length > 0 } {
         HTTP::collect $content_length
      }
   }
}
when HTTP_REQUEST_DATA {
    Do stuff with the payload
   set payload "?[HTTP::payload]"
   if {([URI::query $payload id] equals "sa_sabre") && (([URI::query $payload event] equals "sa_exchangeSrvr_state") || ([URI::query $payload event] equals "sa_sip_state"))} {
        drop
    }
}

```

---

<div class="post-metadata">

**Author:** ![Yann\_Desmarest](https://avatars.discourse-cdn.com/v4/letter/y/5fc32e/32.png) [@Yann\_Desmarest](https://community.f5.com/u/Yann_Desmarest)\
**Post date:** [May 23, 2016, 6:02pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/5 "2016-05-23T18:02:58Z")

</div>

Hi,

There is some encoding errors in the above irule, try this one instead, it’s the same with some fixed encoding chars :

```tcl
when HTTP_REQUEST {
   if { [HTTP::method] eq "POST" } {
       Trigger the collection for up to 1MB of data
      if { [HTTP::header Content-Length] ne "" and [HTTP::header value Content-Length] >= 1048576 } {
         set content_length [HTTP::header value Content-Length]
      } else {
         set content_length 1048576
      }
       Check if $content-length is not set to 0
      if { $content_length > 0 } {
         HTTP::collect $content_length
      }
   }
}
when HTTP_REQUEST_DATA {
    Do stuff with the payload
   set payload "?[HTTP::payload]"
   if {([URI::query $payload id] equals "sa_sabre") && (([URI::query $payload event] equals "sa_exchangeSrvr_state") || ([URI::query $payload event] equals "sa_sip_state"))} {
        drop
    }
}

```

---

<div class="post-metadata">

**Author:** ![Mustafa\_Hashmi](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Mustafa\_Hashmi](https://community.f5.com/u/Mustafa_Hashmi)\
**Post date:** [May 23, 2016, 8:04pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/6 "2016-05-23T20:04:01Z")

</div>

Still getting errors when saving the iRule: 01070151:3: Rule [/Common/Block\_Polycom] error: /Common/Block\_Polycom:18: error: [parse error: PARSE syntax 622 {syntax error in expression “([URI::query $payload id] equals “sa\_sabre”) && (([U…”: variable references require preceding $}][{([URI::query $payload id] equals “sa\_sabre”) && (([URI::query $payload event] equals “sa\_exchangeSrvr\_state”) || ([URI::query $payload event] equals “sa\_sip\_state”))}] LTM is using: 11.6.06.0.442

---

<div class="post-metadata">

**Author:** ![Mustafa\_Hashmi](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Mustafa\_Hashmi](https://community.f5.com/u/Mustafa_Hashmi)\
**Post date:** [May 23, 2016, 8:04pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/7 "2016-05-23T20:04:01Z")

</div>

Still getting errors when saving the iRule: 01070151:3: Rule [/Common/Block\_Polycom] error: /Common/Block\_Polycom:18: error: [parse error: PARSE syntax 622 {syntax error in expression “([URI::query $payload id] equals “sa\_sabre”) && (([U…”: variable references require preceding $}][{([URI::query $payload id] equals “sa\_sabre”) && (([URI::query $payload event] equals “sa\_exchangeSrvr\_state”) || ([URI::query $payload event] equals “sa\_sip\_state”))}] LTM is using: 11.6.06.0.442

---

<div class="post-metadata">

**Author:** ![Mustafa\_Hashmi](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Mustafa\_Hashmi](https://community.f5.com/u/Mustafa_Hashmi)\
**Post date:** [May 23, 2016, 8:08pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/8 "2016-05-23T20:08:14Z")

</div>

OK removed && and replaced with “and” and the iRule saved.

---

<div class="post-metadata">

**Author:** ![Mustafa\_Hashmi](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Mustafa\_Hashmi](https://community.f5.com/u/Mustafa_Hashmi)\
**Post date:** [May 23, 2016, 8:08pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/9 "2016-05-23T20:08:14Z")

</div>

OK removed && and replaced with “and” and the iRule saved.

---

<div class="post-metadata">

**Author:** ![Mustafa\_Hashmi](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Mustafa\_Hashmi](https://community.f5.com/u/Mustafa_Hashmi)\
**Post date:** [May 24, 2016, 4:46pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/10 "2016-05-24T16:46:49Z")

</div>

Thank you for the rule. Question, when applying irule to our resources, we get the following error: 01070394:3: HTTP\_REQUEST event in rule (/Common/Block\_Polycom) requires an associated HTTP or FASTHTTP profile on the virtual server (/Common/vs-TMS-HTTPS). The Virtual server config is: tmsh create ltm virtual vs-TMS-HTTPS {description “TMS Redundancy Virtual Server” destination 10.0.200.40:443 ip-protocol tcp mask 255.255.255.255 pool pl-TMS-HTTPS profiles add {fastL4} source 0.0.0.0/0 source-address-translation {type automap} translate-address enabled translate-port enabled vlans add {internal} vlans-enabled} How can we get this iRule applied to our virtual server?

---

<div class="post-metadata">

**Author:** ![Mustafa\_Hashmi](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Mustafa\_Hashmi](https://community.f5.com/u/Mustafa_Hashmi)\
**Post date:** [May 24, 2016, 4:46pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/11 "2016-05-24T16:46:49Z")

</div>

Thank you for the rule. Question, when applying irule to our resources, we get the following error: 01070394:3: HTTP\_REQUEST event in rule (/Common/Block\_Polycom) requires an associated HTTP or FASTHTTP profile on the virtual server (/Common/vs-TMS-HTTPS). The Virtual server config is: tmsh create ltm virtual vs-TMS-HTTPS {description “TMS Redundancy Virtual Server” destination 10.0.200.40:443 ip-protocol tcp mask 255.255.255.255 pool pl-TMS-HTTPS profiles add {fastL4} source 0.0.0.0/0 source-address-translation {type automap} translate-address enabled translate-port enabled vlans add {internal} vlans-enabled} How can we get this iRule applied to our virtual server?

---

<div class="post-metadata">

**Author:** ![Yann\_Desmarest](https://avatars.discourse-cdn.com/v4/letter/y/5fc32e/32.png) [@Yann\_Desmarest](https://community.f5.com/u/Yann_Desmarest)\
**Post date:** [May 24, 2016, 4:49pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/12 "2016-05-24T16:49:56Z")

</div>

Unfortunately, This irule require an http or fasthttp profile. not fastL4.

---

<div class="post-metadata">

**Author:** ![Yann\_Desmarest\_1](https://avatars.discourse-cdn.com/v4/letter/y/65b543/32.png) [@Yann\_Desmarest\_1](https://community.f5.com/u/Yann_Desmarest_1)\
**Post date:** [May 24, 2016, 4:49pm UTC](https://community.f5.com/t/irule-to-block-http-content/21244/13 "2016-05-24T16:49:56Z")

</div>

Unfortunately, This irule require an http or fasthttp profile. not fastL4.

---

<div class="post-metadata">

**Author:** ![Mustafa\_Hashmi](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Mustafa\_Hashmi](https://community.f5.com/u/Mustafa_Hashmi)\
**Post date:** [May 25, 2016, 4:02am UTC](https://community.f5.com/t/irule-to-block-http-content/21244/14 "2016-05-25T04:02:10Z")

</div>

Can the iRule be modified to use the FastL4?

---

<div class="post-metadata">

**Author:** ![Mustafa\_Hashmi](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@Mustafa\_Hashmi](https://community.f5.com/u/Mustafa_Hashmi)\
**Post date:** [May 25, 2016, 4:02am UTC](https://community.f5.com/t/irule-to-block-http-content/21244/15 "2016-05-25T04:02:10Z")

</div>

Can the iRule be modified to use the FastL4?

---

<div class="post-metadata">

**Author:** ![Yann\_Desmarest\_1](https://avatars.discourse-cdn.com/v4/letter/y/65b543/32.png) [@Yann\_Desmarest\_1](https://community.f5.com/u/Yann_Desmarest_1)\
**Post date:** [May 25, 2016, 6:18am UTC](https://community.f5.com/t/irule-to-block-http-content/21244/16 "2016-05-25T06:18:00Z")

</div>

Hi, unfortunately you need to have a “standard” vs and http profile attached to be able to inspect http

---

<div class="post-metadata">

**Author:** ![Yann\_Desmarest](https://avatars.discourse-cdn.com/v4/letter/y/5fc32e/32.png) [@Yann\_Desmarest](https://community.f5.com/u/Yann_Desmarest)\
**Post date:** [May 25, 2016, 6:18am UTC](https://community.f5.com/t/irule-to-block-http-content/21244/17 "2016-05-25T06:18:00Z")

</div>

Hi, unfortunately you need to have a “standard” vs and http profile attached to be able to inspect http
