Remove Cookie from Request Based on Cookie Domain
I have a web application that will fail if it sees any cookies other than what it knows should be present. I need to scrape/remove all cookies other than that which is required. The required cookie has a semi-dynamic name that could be partially shared with cookies that we do not want. Thus I'm focusing on the cookie domain which I know will be unique. Below is my attempt to complete this. The reason I am not working on the http response is that the other cookies on the client may be required for other applications so I just have to allow only the cookie of interest on the incoming (Request) traffic. The problem I am currently having is that the cookie domain appears to be empty for every incoming cookie. The logging is working properly, but the rule is removing every cookie because the 'cookiedomain' variable is empty. If I change the step 2 logging to "[HTTP::cookie domain $cookie]" it still is blank when outputting the cookie domain. Any help identifying why I am not properly capturing the cookie domain would be much appreciated.
when HTTP_REQUEST {
set cookies [HTTP::cookie names]
foreach cookie $cookies {
log local0. "step 1 - cookie name is $cookie"
set cookiedomain [HTTP::cookie domain $cookie]
log local0. "step 2 - cookie domain is $cookiedomain"
if { $cookiedomain ne "test.mysite.org" }{
log local0. "step 3 - Removing cookie $cookie"
HTTP::cookie remove $cookie
}
}
}