@@ -67,24 +67,29 @@ at least for some parts of the site, e.g. when using forms with
67
67
and clear the session when it is no longer needed. Alternatively, you can look
68
68
into :ref: `caching pages that contain CSRF protected forms <caching-pages-that-contain-csrf-protected-forms >`.
69
69
70
- Cookies created in JavaScript and used only in the frontend, e.g. when using
71
- Google Analytics, are nonetheless sent to the server. These cookies are not
72
- relevant for the backend and should not affect the caching decision. Configure
73
- your Varnish cache to `clean the cookies header `_. You want to keep the
74
- session cookie, if there is one, and get rid of all other cookies so that pages
75
- are cached if there is no active session. Unless you changed the default
76
- configuration of PHP, your session cookie has the name ``PHPSESSID ``:
70
+ Cookies created in JavaScript and used only on the frontend, such as those from
71
+ Google Analytics, are still sent to the server. These cookies are not relevant
72
+ for backend processing and should not influence the caching logic. To ensure
73
+ this, configure your Varnish cache to `clean the cookies header `_ by retaining
74
+ only essential cookies (e.g., session cookies) and removing all others. This
75
+ allows pages to be cached when there is no active session.
76
+
77
+ If you are using PHP with its default configuration, the session cookie is
78
+ typically named ``PHPSESSID ``. Additionally, if your application depends on other
79
+ critical cookies, such as a ``REMEMBERME `` cookie for :doc: `remember me </security/remember_me >`
80
+ functionality or a trusted device cookie for two-factor authentication, these
81
+ cookies should also be preserved.
77
82
78
83
.. configuration-block ::
79
84
80
85
.. code-block :: varnish4
81
86
82
87
sub vcl_recv {
83
- // Remove all cookies except the session ID .
88
+ // Remove all cookies except for essential ones .
84
89
if (req.http.Cookie) {
85
90
set req.http.Cookie = ";" + req.http.Cookie;
86
91
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
87
- set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1=");
92
+ set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID|REMEMBERME )=", "; \1=");
88
93
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
89
94
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
90
95
@@ -98,11 +103,11 @@ configuration of PHP, your session cookie has the name ``PHPSESSID``:
98
103
.. code-block :: varnish3
99
104
100
105
sub vcl_recv {
101
- // Remove all cookies except the session ID .
106
+ // Remove all cookies except for essential ones .
102
107
if (req.http.Cookie) {
103
108
set req.http.Cookie = ";" + req.http.Cookie;
104
109
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
105
- set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1=");
110
+ set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID|REMEMBERME )=", "; \1=");
106
111
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
107
112
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
108
113
0 commit comments