How to configure cookie "secure; http-only;" ?

Hi Folks,

I want to make cookie secure and http only for an SSL url. I have wrote small irule to insert it in header. Does it make sense? Is there any problem we should expect if you are doing it in this way? I saw lot of big irules floating in Devcentral but bit confused now. Please help :slightly_smiling_face:

when HTTP_RESPONSE {
        HTTP::header replace Set-Cookie "[HTTP::header value Set-Cookie];HttpOnly;Secure"
    }

-Freeky

Hello,

You can set the secure flag by using the following lines of codes (within HTTP_RESPONSE event) :

set myValues [HTTP::cookie names]
foreach mycookies $myValues {
    HTTP::cookie secure $mycookies enable
    set value [HTTP::cookie value $mycookies]
    set testvalue [string tolower $value]
    set valuelen [string length $value]
    switch -glob $testvalue {
      "*;httponly*" -
      "*; httponly*" { }
      default { set value "$value; HttpOnly"; }
    }
    if { [string length $value] > $valuelen} {
      HTTP::cookie value $mycookies "${value}"
    }
}