Harborn-digital / cookie-consent-bundle

Symfony bundle to append Cookie Consent to your website to comply to AVG/GDPR for cookies.
MIT License
19 stars 18 forks source link

Cookie display incorrect using Varnish #120

Open sanhofman opened 1 year ago

sanhofman commented 1 year ago

Hi,

When using Cookie Consent Bundle with Varnish, the cookie consent is displayed incorrectly.

We experience two issues:

Using like:

{% if chcookieconsent_isCookieConsentSavedByUser() == false %}
    {{ render_esi(path('ch_cookie_consent')) }}
{% endif %}

In Varnish we strip the cookies correctly:

sub vcl_recv {

    set req.http.Surrogate-Capability = "abc=ESI/1.0";

    if (req.http.Cookie) {
        set req.http.Cookie = ";" + req.http.Cookie;
        set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
        set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1=");
        set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
        set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");

        if (req.http.Cookie == "") {
            # If there are no more cookies, remove the header to get page cached.
            unset req.http.Cookie;
        }
    }