Forum Discussion

Yozzer's avatar
Yozzer
Icon for Nimbostratus rankNimbostratus
Dec 18, 2014

Cookies

Hi

 

Im having an issue with Cookies not being accepted at the server unless they are within the same Cookie header:

 

Cookie: blah=blah; blahs=blahs;

 

If there are two Cookie headers then it ignores the second one (the second one is added in the irule):

 

Cookie: blah=blah other HTTP headers.... Cookie: blahs=blahs.

 

Is it possible to merge all cookies into one Cookie header using an irule and also add a cookie generated within the irule in the merge?

 

Thanks Bryan

 

4 Replies

  • Yozzer's avatar
    Yozzer
    Icon for Nimbostratus rankNimbostratus

    I have:

     

    when HTTP_REQUEST {

     

    Merge cookies and insert cookie that changes the URL

    set hostaddr [HTTP::host]

     

    set existing cookies

    set cookie_names [HTTP::cookie names] if { $cookie_names ne "" } { foreach cookie $cookie_names { set cookie_value [HTTP::cookie $cookie] HTTP::cookie remove $cookie HTTP::cookie insert name $cookie value $cookie_value path / version 1 } } }

     

    But I want to also merge a new cookie generated in the irule such as this:

     

    HTTP::header insert "Cookie" "Url=https://$hostaddr/server.aspx"

     

  • You could grab the header value when it comes in and then append your additional cookie and remove the header then readd it. Something like this...

    set cookie [HTTP::header value "Cookie"]
    HTTP::header remove "Cookie"
    append cookie "; name=value"
    HTTP::insert name Cookie value $cookie
    
  • you could use HTTP::header values instead of value.

    e.g.

     configuration
    
    [root@ve11a:Active:In Sync] config  tmsh 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 12
    }
    [root@ve11a:Active:In Sync] config  tmsh list ltm pool foo
    ltm pool foo {
        members {
            200.200.200.101:80 {
                address 200.200.200.101
            }
        }
    }
    [root@ve11a:Active:In Sync] config  tmsh list ltm rule qux
    ltm rule qux {
        when HTTP_REQUEST {
      set cktmp ""
      foreach ck [HTTP::header values Cookie] {
        if { $cktmp eq "" } {
          append cktmp $ck
        } else {
          append cktmp "; $ck"
        }
      }
      HTTP::header remove Cookie
      HTTP::header insert Cookie $cktmp
    }
    }
    
     test
    
    [root@ve11a:Active:In Sync] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.24.1(57552) <-> 172.28.24.10(80)
    1419065561.2516 (0.0015)  C>S
    ---------------------------------------------------------------
    GET / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: 172.28.24.10
    Accept: */*
    cookie: blah=blah
    cookie: blahs=blahs
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.14(57552) <-> 200.200.200.101(80)
    1419065561.2534 (0.0016)  C>S
    ---------------------------------------------------------------
    GET / HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
    Host: 172.28.24.10
    Accept: */*
    Cookie: blah=blah; blahs=blahs
    
    ---------------------------------------------------------------