Technical Forum
Ask questions. Discover Answers.
cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to find a way to delete cookie with a domain name using irule

rajb
Nimbostratus
Nimbostratus

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

rajb_0-1676413253449.png

 

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

14 REPLIES 14

Paulius
MVP
MVP

@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}
            }
                       
        }

    }

}

 

Hey @Paulius I tried the above, however, the variable CookieDomain is empty when I try to print it to the log. 

@rajb At what line in the iRule do you have the log entry? If you can provide the iRule that you have configured we might be able to figure out why that's occurring.

rajb
Nimbostratus
Nimbostratus

@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}"

@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 :

@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.

My replies are disappearing not sure why

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.  

@Leslie_Hubertus Hello - Sorry for the inconvenience. May I know how to delete the duplicates ? 

I don't see an option to delete the duplicates

No, the apology is mine to make, @rajb - I got my permissions settings messed up. Sorry about that! I got rid of the duplicates that had no reply. 

@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:

markebeast
Nimbostratus
Nimbostratus

I tried the above, however, the variable CookieDomain is empty when I try to print it to the log. 

markebeast
Nimbostratus
Nimbostratus

I don't see an option to delete the duplicates  vidmate 2014

mobdro app