Forum Discussion

Dave_Gerke_2110's avatar
Dave_Gerke_2110
Icon for Nimbostratus rankNimbostratus
Oct 29, 2007

Cookie Irule Help

IE is blocking cookies for a url because the host name the client comes in on is different than the host name inside the cookie. Client connects on www.xyz.com and a cookie is sent with a host name inside of www.abc.com. The cookie also contains specific customer information, which enables the client to land on a login page with the correct logo. I believe because the host name being sent back in the cookie is different, IE is blocking it when privacy setting is on medium. I need to write an irule which changes the host name inside the cookie back to the original request host name, and then back when the client reconnects. Any help would be greatly appreciated.

7 Replies

  • Hi,

    A cookie in the HTTP request doesn't have a domain, so you'd only need to modify the domain in responses. You can get or set the domain on a cookie in the response using "HTTP::cookie domain [domain]" (Click here).

    Here is an example:

    
    when HTTP_RESPONSE {
        check if the cookie is being set
       if {[HTTP::cookie exists "some_cookie"}{
           set the domain of the cookie to domain_to_set
          HTTP::cookie domain some_cookie domain_to_set
       }
    }

    Can you give this a shot?

    Aaron
  • Thanks for your response. Can you tell me if what I have below would work? If a ceretain cookie exists I want to change the domain name from abc to xyz.

     

     

     

    when HTTP_RESPONSE {

     

     

    if {[HTTP::cookie exists abcPlanCode}{

     

     

    HTTP::cookie domain www.abc.com www.xyz.com

     

    }

     

    }

     

  • That's close. The first variable for HTTP::cookie domain should be the cookie name you want to modify. This should work:

    
    when HTTP_RESPONSE {
       if {[HTTP::cookie exists abcPlanCode}{
          HTTP::cookie domain abcPlanCode www.xyz.com
       }
    }

    Aaron
  • Thank you very much. So the net result is that when a client connects the server sends a cookie, f5 will rewrite the cookie with the same domain name that the client came in on instead of the domain that is inside the cookie? Just want to make sure I am 100% Sorry I am familiar with irule redirects etc....but have never done anything with cookie rewrites.
  • Assuming what you replace www.xyz.com with in the iRule is the domain the client is making the request to, then yes.

     

     

    Aaron
  • Sorry it has been a while between my post. Thank you for the information. I have one other question though. If I only want the cookie manipulated if the url it comes in on is is www.abc.com and every other url it comes in on I do not want to manipulate. What should I do?
  • This should work to only perform the domain change on the cookie sent by the web app if the request is made to www.abc.com:

    
    when HTTP_REQUEST {
       if {[string tolower [HTTP::host]] eq "www.abc.com"}{
          set update_cookie 1
       } else {
          set update_cookie 0
       }
    }
    when HTTP_RESPONSE {
       if {$update_cookie and [HTTP::cookie exists abcPlanCode]}{
          HTTP::cookie domain abcPlanCode www.xyz.com
       }
    }

    Aaron