Forum Discussion
Trying to find a way to delete cookie with a domain name using irule
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 :
- PauliusFeb 15, 2023MVP
rajb What happens if you add the following just before you "Domain name is:" logging line?
log local0. "Cookie name is: ${cookie_name}"
- rajbFeb 15, 2023Nimbostratus
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 :
- PauliusFeb 16, 2023MVP
rajb Try out this iRule and internal data-group to see if it works for you.
when HTTP_REQUEST priority 500 { # Check if we have already deleted the cookies log local0. "Running within HTTP_REQUEST" if {![HTTP::cookie exists tracking_cookie]} { log local0. "Running within tracking_cookie" foreach a_cookie [HTTP::cookie names] { # Compares the cookie name to the internal data-group list called CLASS-CookieList if { [class match -- [HTTP::cookie name ${a_cookie}] == CLASS-CookieList] } { set CookieDomain [HTTP::cookie domain ${a_cookie}] log local0. "Executing cookie: ${a_cookie}" log local0. "Domain name is: ${CookieDomain}" } } } }
The following data-group can be loaded into your configuration by using "load sys config from-terminal merge" without the quotations. You will see a prompt that shows you the key sequence to press to commit the change you are loading in. Make sure it is the exact command less the quotation marks.
ltm data-group internal CLASS-CookieList { records { CruisingListingsFilter { } GuysOnlineFilter { } _ga { } _gid { } loadedFromBrowserCache { } notifycached { } } type string }
I am interested in knowing what the logs show after using this iRule if you can parse the logs for your iRule name which seems to be called "delete_cookie_test" on your F5.
- rajbFeb 15, 2023Nimbostratus
My replies are disappearing not sure why
- Leslie_HubertusFeb 16, 2023Ret. Employee
Hey rajb - it looks like you tries posting the same content multiple times times, and that triggered the automated spam filter. I've released all the posts, and ask that you please delete the duplicates here.
- rajbFeb 16, 2023Nimbostratus
Paulius This the updated irule and the output
when HTTP_REQUEST { # Check if we have already deleted the cookies log local0. "Running within HTTP_REQUEST" if {not [HTTP::cookie exists tracking_cookie]} { log local0. "Running within tracking_cookie" # Define an array of cookie names to delete set cookie_names [list "loadedFromBrowserCache" "_gid" "_ga" "GuysOnlineFilter" "CruisingListingsFilter" "notifycached"] foreach cookie_name $cookie_names { set cookieDomain [HTTP::cookie domain "${cookie_name}"] log local0. "Executing cookie: ${cookie_name}" log local0. "Domain name is: ${cookieDomain}" } } } Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Running within HTTP_REQUEST Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Running within tracking_cookie Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Executing cookie: loadedFromBrowserCache Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is: Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Executing cookie: _gid Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is: Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Executing cookie: _ga Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is: Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Executing cookie: GuysOnlineFilter Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is: Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Executing cookie: CruisingListingsFilter Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is: Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Executing cookie: notifycached Feb 16 10:15:28 lb1.ptp.local info tmm1[19397]: Rule /Common/delete_cookie_test <HTTP_REQUEST>: Domain name is:
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