Skip to content

Commit 9b50440

Browse files
Hulutijaviereguiluz
authored andcommittedJan 2, 2025·
Add info for essential cookies (such as REMEMBERME)
1 parent ec1415e commit 9b50440

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed
 

‎http_cache/varnish.rst

+5-8
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,18 @@ into :ref:`caching pages that contain CSRF protected forms <caching-pages-that-c
7070
Cookies created in JavaScript and used only in the frontend, e.g. when using
7171
Google Analytics, are nonetheless sent to the server. These cookies are not
7272
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``:
73+
your Varnish cache to `clean the cookies header`_. The goal is to retain only essential cookies—such as session cookies—and remove all others. By doing this, pages can still be cached when there is no active session. If you are using PHP and have not changed its default configuration, the session cookie is typically named PHPSESSID. Additionally, if your application relies on other important cookies, such as a "REMEMBERME" cookie for "remember me" functionality or "trusted_device" for 2FA, these cookies should also be preserved.
7774

7875
.. configuration-block::
7976

8077
.. code-block:: varnish4
8178
8279
sub vcl_recv {
83-
// Remove all cookies except the session ID.
80+
// Remove all cookies except for essential ones.
8481
if (req.http.Cookie) {
8582
set req.http.Cookie = ";" + req.http.Cookie;
8683
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
87-
set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1=");
84+
set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID|REMEMBERME)=", "; \1=");
8885
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
8986
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
9087
@@ -98,11 +95,11 @@ configuration of PHP, your session cookie has the name ``PHPSESSID``:
9895
.. code-block:: varnish3
9996
10097
sub vcl_recv {
101-
// Remove all cookies except the session ID.
98+
// Remove all cookies except for essential ones.
10299
if (req.http.Cookie) {
103100
set req.http.Cookie = ";" + req.http.Cookie;
104101
set req.http.Cookie = regsuball(req.http.Cookie, "; +", ";");
105-
set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID)=", "; \1=");
102+
set req.http.Cookie = regsuball(req.http.Cookie, ";(PHPSESSID|REMEMBERME)=", "; \1=");
106103
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
107104
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
108105

0 commit comments

Comments
 (0)
Please sign in to comment.