Forum Discussion
Trying to find a way to delete cookie with a domain name using irule
Hello,
I'm trying to delete cookie that have a domain name set. For example in the below pciture, there are cookies with domain name reddit, let's say I'd like to delete it with an irule
I checked the documentation and wrote the below irule to test but it doesn't seem to work. Any ideas why it doesn't work ?
when HTTP_REQUEST {
set cookie_names [HTTP::cookie names]
foreach a_cookie $cookie_names {
if { $a_cookie equals "GuysOnlineFilter" } {
if { [HTTP::cookie domain $a_cookie] contains ".sq.org" } {
log local0. "it's working"
#reemove the cookie here
}
}
}
}
Appreciate if anyone could help
rajb I believe the following iRule would work for you but please keep in mind that when you compare "GuysOnlineFilter" text it must be that exact text string, so It has to have those capitalized letters otherwise it will not match and it will do nothing. I recommend testing this in a lab evironment or on a test virtual server to ensure it is working as expected before applying to a production virtual server.
when HTTP_REQUEST priority 500 { foreach a_cookie [HTTP::cookie names] { set CookieDomain [HTTP::cookie domain ${a_cookie}] if { ${a_cookie} == "GuysOnlineFilter" } { if { [HTTP::cookie domain ${CookieDomain}] contains ".sq.org" } { log local0. "it's working" HTTP::cookie remove ${a_cookie} } } } }
- rajbNimbostratus
Paulius For example: I have the following irule
when HTTP_REQUEST { # Check if we have already deleted the cookies if {not [HTTP::cookie exists tracking_cookie]} { # Define an array of cookie names to delete set cookie_names [list "loadedFromBrowserCache" "_gid" "_ga" "GuysOnlineFilter" "CruisingListingsFilter" "notifycached"] # Loop through each cookie name and delete it if it exists in the ".squirt.org" domain foreach cookie_name $cookie_names { set CookieDomain [HTTP::cookie domain ${cookie_name}] log local0. "Domain name is : ${CookieDomain}" if {[HTTP::cookie exists ${cookie_name}] and ${CookieDomain} contains ".sq.org"} { HTTP::cookie remove ${cookie_name} domain ".sq.org" } } # Set the tracking cookie to ensure we only delete the cookies once HTTP::cookie insert name tracking_cookie value "true" domain ".sq.org" HTTP::cookie attribute dummy_cookie value "expires" "Sun, 26-Feb-2023 00:00:00 GMT" #HTTP::cookie expires tracking_cookie "1676476831" } }
In the tmm log I see the variable as empty
Feb 15 12:29:11 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is : Feb 15 12:29:11 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is : Feb 15 12:29:11 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is : Feb 15 12:29:11 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is : Feb 15 12:29:11 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is : Feb 15 12:29:11 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is :
rajb What happens if you add the following just before you "Domain name is:" logging line?
log local0. "Cookie name is: ${cookie_name}"
- rajbNimbostratus
Paulius I get the following in the logs
Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Cookie name is: loadedFromBrowserCache Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is : Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Cookie name is: _gid Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is : Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Cookie name is: _ga Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is : Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Cookie name is: GuysOnlineFilter Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is : Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Cookie name is: CruisingListingsFilter Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is : Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Cookie name is: notifycached Feb 15 13:04:37 lb1.ptp.local info tmm2[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is :
- markebeastNimbostratus
I tried the above, however, the variable CookieDomain is empty when I try to print it to the log.
- markebeastNimbostratus
I don't see an option to delete the duplicates vidmate 2014
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