Scott C
Scott C

Reputation: 1

netscaler check if cookie exists

I'm trying to use Citrix Netscaler to check for the existence of a specific cookie. It seems like it should be straightforward but I've had no success so far.

Specifically, I want to check for the cookie's existence in a Responder Policy and, if the cookie is not found, redirect the user to a specific page. A JavaScript script on that page will then create the cookie so that the redirect will not be triggered on the next visit. The idea is to redirect the user to a page with a message, but only once within the expiry of the cookie.

I'm comfortable with setting up Responder Polices and Actions but havent been able to get the cookie check to work as desired. I can see in Firefox developer view that the cookie is created as expected.

I'm working with a Netscaler MPX with version 10.5


I searched extensively but had no luck finding an answer that works, or at least that I understand and can apply. I also searched on the Citrix Netscaler community and read through the NS documentation.

The closest approach I was able to come up with so far is something like

!HTTP.REQ.COOKIE.CONTAINS("myCookie")

which I had expected would see the presence of the cookie and not fire the policy due to the !. I tried with .NOT and the end of the statement instead of the ! but had no luck.

I tested that the cookies are being read by using

HTTP.REQ.COOKIE.LENGTH < or > some arbitray value 

and I can see that it is properly evaluated and the logic works as expected. According to the documentation HTTP.REQ.COOKIE returns a Name/Value List with the contents of the HTTP Cookie header, so I expected .CONTAINS to evaluate to true if the cookie name was found. This doesn't seem to be the case.

Upvotes: 0

Views: 3673

Answers (2)

Vaishnavi V
Vaishnavi V

Reputation: 21

I know this is too late to reply. But this may help someone with similar query.

HTTP.REQ.COOKIE.NAMES.CONTAINS_ELEMENT("myCookie").NOT

is the expression you would be looking for. This returns true if the cookie is not present.

HTTP.REQ.COOKIE.NAMES is a list of cookie names present in the HTTP Request. HTTP.REQ.COOKIE.NAMES.CONTAINS_ELEMENT("myCookie") returns true if mycookie is present. exact string match (EQ) is preformed instead of pattern match (CONTAINS).

Upvotes: 2

Guna.K
Guna.K

Reputation: 1

I think the closest that you can get is to check for the length of value of that cookie. Try using

HTTP.REQ.HEADER(\"myCookie\").LENGTH >1

Upvotes: 0

Related Questions