Forum Discussion

venkatraman01's avatar
venkatraman01
Icon for Nimbostratus rankNimbostratus
Feb 10, 2023

Modify cookie path for top level domain

Hi All -

I am writing an irule to modify the cookie path for the top level domain.    Basically we have two web portals - p1.abc.com and p2.abc.com.   By default all the traffic hits on p1.abc.com and once the traffic reaches the web server it redirects the user to p2.abc.com for certain use cases.    Right now the cookie path is set to p1.abc.com and i am trying to change the cookie path to .abc.com along with few more validations.   I tried this irule but it does not work.     Any suggestions.

 
when HTTP_RESPONSE {
             set newdomain ".abc.com"
foreach jsessionid [HTTP::cookie names] {
              if {($jsessionid contains "JSESSIONID") && ([HTTP::cookie domain] ends_with "p1.abc.com") && ([HTTP::cookie path] contains "/Buyer" or "/Sourcing")} {
              HTTP::cookie domain $jsessionid $newdomain
}

}
}

 

  • venkatraman01 I believe the following will achieve what you would like for both p1 and p2.

    when HTTP_RESPONSE priority 500 {
    
        set newdomain ".abc.com"
    
        foreach jsessionid [HTTP::cookie names] {
    
            set cookieDomain [HTTP::cookie domain ${jsessionid}]
    
            if { ((${cookieDomain} contains ${newdomain}) && (([HTTP::cookie path] contains "/Buyer") or ([HTTP::cookie path] contains "/Sourcing"))) } {
                HTTP::cookie domain ${jsessionid} ${newdomain} 
            }
    
        }
    
    }
    • Leslie_Hubertus's avatar
      Leslie_Hubertus
      Ret. Employee

      Hi venkatraman01  - did Paulius' reply help? If yes, please click the Accept as Solution button so future users looking for help with the same problem can easily find help in the Search. 🙂