# xss attack

**URL:** <https://community.f5.com/t/xss-attack/1491>\
**Category:** Technical Forums\
**Tags:** dev, irules, devops, application-delivery\
**Created:** [October 16, 2009, 3:34pm UTC](https://community.f5.com/t/xss-attack/1491 "2009-10-16T15:34:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gustavo\_Lazarte](https://avatars.discourse-cdn.com/v4/letter/g/ba9def/32.png) [@Gustavo\_Lazarte](https://community.f5.com/u/Gustavo_Lazarte)\
**Post date:** [October 16, 2009, 3:34pm UTC](https://community.f5.com/t/xss-attack/1491/1 "2009-10-16T15:34:03Z")

</div>

Hello,

we need to take out the “script” or

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [October 16, 2009, 4:05pm UTC](https://community.f5.com/t/xss-attack/1491/2 "2009-10-16T16:05:25Z")

</div>

You can try to filter the URI using an iRule, but an attacker will be able to obfuscate their attack using many encoding schemes that the web server will probably parse and you won’t be able to track in an iRule. An attacker could probably also send the malicious strings in the payload in POST requests. It would be very difficult to handle these scenarios in an iRule and still support typical production levels of traffic.

If you want to check if the decoded URI contains “script”, you could use something like this (from Joe’s Codeshare example [Click here](http://devcentral.f5.com/wiki/default.aspx/iRules/FullyDecodeURI.html)😞

```tcl
when HTTP_REQUEST { 
  
     URI decode the URI 
    set tmpUri [HTTP::uri] 
    set uri [URI::decode $tmpUri] 
  
     repeat decoding until the decoded version equals the previous value. 
    while { $uri ne $tmpUri } { 
       set tmpUri $uri 
       set uri [URI::decode $tmpUri] 
    } 
    if {[string tolower $uri] contains "script"]}{ 
  
        Found script in the decoded URI. Do something? 
       HTTP::respond 404 
    } 
 }

```

Aaron

---

<div class="post-metadata">

**Author:** ![hoolio](https://avatars.discourse-cdn.com/v4/letter/h/f6c823/32.png) [@hoolio](https://community.f5.com/u/hoolio)\
**Post date:** [October 16, 2009, 4:09pm UTC](https://community.f5.com/t/xss-attack/1491/3 "2009-10-16T16:09:15Z")

</div>

I should add that the best way to handle this efficiently and securely is to use a web app firewall and fix the application code. Trying to use an iRule to implement HTTP security is not going to be both efficient and complete.

Aaron
