Mailing List Archive

Set cookie creating issues
Hi,

We have been using Varnish for caching our web pages. We have an
ecommerce site. Things have been working fine till today but suddenly
things have started breaking down and I am not sure why. Following is
the issue:

We use session cookie to store user sessions. The session cookie is
getting changed as Cached responses from varnish is having set-cookie
header which is messing up the session cookie. We are using varnish 4.8.
Following is a snippet of the VCL:


sub vcl_recv {
# Happens before we check if we have this in cache already.
#
# Typically you clean up the request here, removing cookies you
don't need,
# rewriting the request, etc.
set req.backend_hint = uwsgi;

#if (req.http.cookie ~ "jivaana_country=") {
# Set the country header
# set req.http.X-CLIENT-COUNTRY = regsub(req.http.cookie,
".*jivaana_country=([^;]+);.*", "\1");
# }

std.log("ga:" + ga.extract(req.url, mode = keep));
set req.url = ga.apply(req.url); # remove Google Analytics parameters

if (req.method == "GET") {
if ((req.url !~ "^/accounts/userheader") &&
(req.url !~ "^/accounts/new-userheader") &&
(req.url !~ "^/product/recently-viewed") &&
(req.url !~ "^/product/recommended-products") &&
(req.url !~ "^/product/addtobasket")) {
unset req.http.cookie; # strip the cookies - we don't
need them
}
}

call devicedetect;
}

sub vcl_backend_response {
# Happens after we have read the response headers from the backend.
#
# Here you clean the response headers, removing silly Set-Cookie
headers
# and other mistakes your backend does.
if (bereq.method == "GET") {
set beresp.do_esi = true;
if ((bereq.url !~ "^/accounts/userheader") &&
(bereq.url !~ "^/accounts/new-userheader") &&
(bereq.url !~ "^/product/recently-viewed") &&
(bereq.url !~ "^/product/recommended-products") &&
(bereq.url !~ "^/product/addtobasket")) {
#unset beresp.http.Set-Cookie;
set beresp.uncacheable = false;
#std.log("Caching the url : **********************" +
bereq.url);
}
}

sub vcl_deliver {
# Happens when we have all the pieces we need, and are about to
send the
# response to the client.
#
# You can do accounting or modifying the final object here.
}

sub vcl_hash {
}

Would really appreciate any support as this is messing up our user sessions.

Thanks,

Pinakee

_______________________________________________
varnish-misc mailing list
varnish-misc@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
Re: Set cookie creating issues [ In reply to ]
Hi,

That's really going to be hard to debug without some logs. Anyway, your vcl
doeesn't unset set-cookie headers, so you can expect you cached objects to
wreck some havoc since they will be reused for multiple clients.

Regards,

--
Guillaume Quintard

On Fri, Apr 27, 2018 at 4:57 PM, Pinakee BIswas <pinakee@waltzz.com> wrote:

> Hi,
>
> We have been using Varnish for caching our web pages. We have an ecommerce
> site. Things have been working fine till today but suddenly things have
> started breaking down and I am not sure why. Following is the issue:
>
> We use session cookie to store user sessions. The session cookie is
> getting changed as Cached responses from varnish is having set-cookie
> header which is messing up the session cookie. We are using varnish 4.8.
> Following is a snippet of the VCL:
>
>
> sub vcl_recv {
> # Happens before we check if we have this in cache already.
> #
> # Typically you clean up the request here, removing cookies you don't
> need,
> # rewriting the request, etc.
> set req.backend_hint = uwsgi;
>
> #if (req.http.cookie ~ "jivaana_country=") {
> # Set the country header
> # set req.http.X-CLIENT-COUNTRY = regsub(req.http.cookie,
> ".*jivaana_country=([^;]+);.*", "\1");
> # }
>
> std.log("ga:" + ga.extract(req.url, mode = keep));
> set req.url = ga.apply(req.url); # remove Google Analytics parameters
>
> if (req.method == "GET") {
> if ((req.url !~ "^/accounts/userheader") &&
> (req.url !~ "^/accounts/new-userheader") &&
> (req.url !~ "^/product/recently-viewed") &&
> (req.url !~ "^/product/recommended-products") &&
> (req.url !~ "^/product/addtobasket")) {
> unset req.http.cookie; # strip the cookies - we don't need
> them
> }
> }
>
> call devicedetect;
> }
>
> sub vcl_backend_response {
> # Happens after we have read the response headers from the backend.
> #
> # Here you clean the response headers, removing silly Set-Cookie
> headers
> # and other mistakes your backend does.
> if (bereq.method == "GET") {
> set beresp.do_esi = true;
> if ((bereq.url !~ "^/accounts/userheader") &&
> (bereq.url !~ "^/accounts/new-userheader") &&
> (bereq.url !~ "^/product/recently-viewed") &&
> (bereq.url !~ "^/product/recommended-products") &&
> (bereq.url !~ "^/product/addtobasket")) {
> #unset beresp.http.Set-Cookie;
> set beresp.uncacheable = false;
> #std.log("Caching the url : **********************" +
> bereq.url);
> }
> }
>
> sub vcl_deliver {
> # Happens when we have all the pieces we need, and are about to send
> the
> # response to the client.
> #
> # You can do accounting or modifying the final object here.
> }
>
> sub vcl_hash {
> }
>
> Would really appreciate any support as this is messing up our user
> sessions.
>
> Thanks,
>
> Pinakee
>
> _______________________________________________
> varnish-misc mailing list
> varnish-misc@varnish-cache.org
> https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
>