Forum Discussion
iRule to rewrite cookie domain to toplevel domain
- Mar 18, 2016
Finally I was able to set the cookie domain to toplevel by using the following iRule. Cookies are set to toplevel domain now by using HTTP::host and comparing directly with the domain values I have. What do you think about the following iRule? Any flaws?
when HTTP_REQUEST { log local0. "Cookie names in received request: [HTTP::cookie names] from IP: [IP::local_addr]" set httphost [HTTP::host] } when HTTP_RESPONSE { foreach mycookie [HTTP::cookie names] { log local0. "Host : $httphost" if { $httphost ends_with ".abc.com" } { HTTP::cookie domain $mycookie ".abc.com" } elseif { $httphost ends_with ".abbc.com" } { HTTP::cookie domain $mycookie ".abbc.com" } else { log local0. "Not a single cookie domain matched :" } } }
Finally I was able to set the cookie domain to toplevel by using the following iRule. Cookies are set to toplevel domain now by using HTTP::host and comparing directly with the domain values I have. What do you think about the following iRule? Any flaws?
when HTTP_REQUEST {
log local0. "Cookie names in received request: [HTTP::cookie names] from IP: [IP::local_addr]"
set httphost [HTTP::host]
}
when HTTP_RESPONSE {
foreach mycookie [HTTP::cookie names] {
log local0. "Host : $httphost"
if { $httphost ends_with ".abc.com" } {
HTTP::cookie domain $mycookie ".abc.com"
} elseif { $httphost ends_with ".abbc.com" } {
HTTP::cookie domain $mycookie ".abbc.com"
} else {
log local0. "Not a single cookie domain matched :"
}
}
}
- Sylvain_85827Mar 21, 2016
Cirrus
Just remember when you go live with iRule to remove all log entries and the final else that will become useless. when HTTP_REQUEST { set httphost [HTTP::host] } when HTTP_RESPONSE { foreach mycookie [HTTP::cookie names] { if { $httphost ends_with ".abc.com" } { HTTP::cookie domain $mycookie ".abc.com" } elseif { $httphost ends_with ".abbc.com" } { HTTP::cookie domain $mycookie ".abbc.com" } } }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com