Forum Discussion

Mike_Breeden_62's avatar
Mike_Breeden_62
Icon for Nimbostratus rankNimbostratus
Apr 30, 2014

Rewrite IE11 user agent

We have a situation where any IE11 users outside our company going to Microsoft Exchange OWA are forced to use the light version of OWA since it does not see IE11 as a compatible browser version.

 

I would like to create an iRule that will rewrite the user agent string and add MSIE 11.0 to the end of the string.

 

Since we have no way of testing in a dev environment I would like to also apply a datagroup check to limit the rule to specific ip address so that I can test without harming production.

 

Does anyone have an iRule for this?

 

4 Replies

  • check this https://devcentral.f5.com/questions/need-to-change-http-header-depending-on-pool-member-selected that might work where you can to replace for user agent vs. host

     

  • e.g.

     config
    
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:80
        ip-protocol tcp
        mask 255.255.255.255
        pool foo
        profiles {
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 9
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo
    ltm pool foo {
        members {
            200.200.200.101:80 {
                address 200.200.200.101
            }
        }
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      if { [class match -- [IP::client_addr] eq testip_class] } {
        HTTP::header replace "User-Agent" "whatever"
      }
    }
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm data-group internal testip_class
    ltm data-group internal testip_class {
        records {
            192.168.206.0/24 { }
        }
        type ip
    }
    
     trace
    
    [root@ve11a:Active:In Sync] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 192.168.206.35(64425) <-> 172.28.24.10(80)
    1398869916.2194 (0.0041)  C>S
    ---------------------------------------------------------------
    GET / HTTP/1.1
    Host: 172.28.24.10
    User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:28.0) Gecko/20100101 Firefox/28.0
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.14(64425) <-> 200.200.200.101(80)
    1398869916.3089 (0.0869)  C>S
    ---------------------------------------------------------------
    GET / HTTP/1.1
    Host: 172.28.24.10
    User-Agent: whatever
    Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    Accept-Language: en-US,en;q=0.5
    Accept-Encoding: gzip, deflate
    Connection: keep-alive
    
    ---------------------------------------------------------------
    
  • I just want to be able to rewrite the user agent like so. I would like to limit the iRule during testing with an class match that looks at a datagroup that will have specific ips that this iRule will apply to.

     

    Current User agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko New User agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0; MSIE 11.0) like Gecko

     

  • e.g.

     config
    
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
    ltm virtual bar {
        destination 172.28.24.10:80
        ip-protocol tcp
        mask 255.255.255.255
        pool foo
        profiles {
            http { }
            tcp { }
        }
        rules {
            qux
        }
        source 0.0.0.0/0
        source-address-translation {
            type automap
        }
        vs-index 9
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo
    ltm pool foo {
        members {
            200.200.200.101:80 {
                address 200.200.200.101
            }
        }
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm data-group internal testip_class
    ltm data-group internal testip_class {
        records {
            172.28.24.0/24 { }
            192.168.206.0/24 { }
        }
        type ip
    }
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qu
    Configuration Items:
      qux       qux1813   qux80
    root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      if { [class match -- [IP::client_addr] eq testip_class] } {
        if { !([string tolower [HTTP::header User-Agent]] contains "msie 11.0") } {
          HTTP::header replace "User-Agent" [string map {")" "; MSIE 11.0)"} [HTTP::header User-Agent]]
        }
      }
    }
    }
    
     trace
    
    [root@ve11a:Active:In Sync] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.24.1(34504) <-> 172.28.24.10(80)
    1398915199.2349 (0.0025)  C>S
    ---------------------------------------------------------------
    GET / HTTP/1.1
    Host: 172.28.24.10
    Accept: */*
    User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.14(34504) <-> 200.200.200.101(80)
    1398915199.2367 (0.0016)  C>S
    ---------------------------------------------------------------
    GET / HTTP/1.1
    Host: 172.28.24.10
    Accept: */*
    User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0; MSIE 11.0) like Gecko
    
    ---------------------------------------------------------------