The web administrators may force Secure and/or HttpOnly flags on the Session ID and the authentication cookies that are generated by the web applications. Modifying Set-Cookie headers to include these two options can be done using an http Load Balancing Virtual Server and Rewrite Policies on a Netscaler appliance.
Important! You cannot use the HttpOnly option when a web application requires access to Cookie contents by using a client-side script such as JavaScript or a client-side Java Applet. From the method mentioned in this article, only server-generated cookies can be rewritten, not the cookies generated by NetScaler Appliance (for ex: AppFirewall, persistence, VPN session cookies, and so on)
HttpOnly flag on NSC_AAAC and NSC_TMAS cookies is available in the 13.0-79.x and later releases (disabled and hidden by default).
Use the following commands to enable/disable the feature.
Note: This procedure is not applicable to VPN Vservers.
To configure the NetScaler appliance to force the Secure and HttpOnly flags for an existing HTTP virtual server, complete the following steps:
Go to Rewrite > Actions, and then click add to add a new rewrite action.
Go to Rewrite > Policies and then click add to add a new Rewrite policy.
Go to Load Balancing > Virtual Servers and then bind the Rewrite (Response) policy to the corresponding SSL VServer.
Create a rewrite action (this example is configured to set both Secure and HttpOnly flags. If either one is missing, modify it as necessary for other combinations).
add rewrite action act_cookie_Secure replace_all http.RES.full_Header "\"Secure; HttpOnly; path=/\"" -search "regex(re!(path=/\\; Secure; HttpOnly)|(path=/\\; Secure)|(path=/\\; HttpOnly)|(path=/)!)" -bypassSafetyCheck YES
This policy will replace all instances of "path=/", "path=/; Secure", "path=/; Secure; HttpOnly" and "path=/; HttpOnly" with "Secure; HttpOnly; path=/". Note that this regex fail if the case doesn't match.
Create a rewrite policy to trigger the action.
add rewrite policy rw_force_secure_cookie "http.RES.HEADER(\"Set-Cookie\").EXISTS" act_cookie_Secure
Bind the rewrite policy to the VServer to be secured (if Secure option is used, an SSL VServer should be used).
bind lb vserver mySSLVServer -policyName rw_force_secure_cookie -priority 100 -gotoPriorityExpression NEXT -type RESPONSE
Example:
Before Rewrite:< Set-Cookie: CtxsAuthId=C5614491; path=/Citrix/ProdWeb/
After Rewrite: < Set-Cookie: CtxsAuthId=C5614491; Secure; HttpOnly; path=/Citrix/ProdWeb/