Forum Discussion

Oliviattt_32197's avatar
Oliviattt_32197
Icon for Nimbostratus rankNimbostratus
May 25, 2017

F5 iRule to Secure Cookie with HTTPOnly and Secure but not contains cookie name="cnlfsid"

Hi, We need to Secure Cookie with HTTPOnly and Secure but not contains a cookie name ="cnlfsid"

 

Here is my code:

 

when HTTP_RESPONSE {

 

foreach x [HTTP::cookie names] {

 

set ckname $x set ckvalue [HTTP::cookie value $x] set ckpath [HTTP::cookie value path]

 

            if{!($ckname equals "cnlfsid")} {
                    HTTP::cookie remove $x
                    HTTP::cookie insert name $ckname value $ckvalue path $ckpath version 1
                    HTTP::cookie secure $ckname enable
                    HTTP::cookie httponly $ckname enable    
            }
}

}

 

but it can't work. Can someone help me to fix it.

 

Many thanks

 

  • JG's avatar
    JG
    Icon for Cumulonimbus rankCumulonimbus

    Try this modified version:

    when HTTP_RESPONSE {
        foreach x [HTTP::cookie names] {
            if { $x equals "cnlfsid" } {
                continue
            }
            set ckname $x
            set ckvalue [HTTP::cookie value $x] 
            set ckpath [HTTP::cookie $x path]
            HTTP::cookie remove $x
            HTTP::cookie insert name $ckname value $ckvalue path $ckpath version 1
            HTTP::cookie secure $ckname enable
            HTTP::cookie httponly $ckname enable
        }
    }
    

    .