Forum Discussion

jaiAdityaSingla's avatar
jaiAdityaSingla
Icon for Nimbostratus rankNimbostratus
Jan 28, 2016

Check the VS port to determine if connection is SSL or not, help me to fix it

when CLIENT_ACCEPTED {

 

Check the VS port to determine if connection is SSL or not

switch [TCP::local_port] { "443" { set proto "https" } default { set proto "http" } }} when HTTP_RESPONSE { set chk_cookies [HTTP::cookie names] foreach cookie $chk_cookies { Rewrite Cookies to ensure the version is Cookie version is correct set cookie_value [HTTP::cookie $cookie] HTTP::cookie remove $cookie HTTP::cookie insert name $cookie value $cookie_value path / version 1 Set HttpOnly for all cookies HTTP::cookie httponly $cookie enable Set Secure if connection is SSL if {$proto=="https"}{ HTTP::cookie secure $cookie enable } }}

 

1 Reply

  • Hi jaiAdityaSingla,

    I would change the code to...

     

    when CLIENT_ACCEPTED {
         Check the VS port to determine if connection is SSL or not
        if { [TCP::local_port] eq "443" } then {
            set secure_cookie "; Secure"
        } else {
            set secure_cookie ""
        }
    }
    when HTTP_RESPONSE {
        foreach temp(cookie) [HTTP::cookie names] {
             Rewrite Cookies to ensure the version is Cookie version is correct
            set temp(cookie_value) [HTTP::cookie $cookie]
            HTTP::cookie remove $cookie
            HTTP::header insert Set-Cookie "$temp(cookie)=\"$temp(cookie_value)\"; Version=1; HttpOnly$secure_cookie; Path=/"
        }
    }
    

     

    Note1: The code would insert a raw Set-Cookie header, with precomputed cookie options.

    Note2: The "; Secure" option is getting substituted using the results of the CLIENT_ACCEPTED event.

    Cheers, Kai