Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dec15d9

Browse filesBrowse files
committed
Merge branch '7.2' into 7.3
* 7.2: Minor tweaks Add info for essential cookies (such as REMEMBERME)
2 parents b198f77 + db859ae commit dec15d9
Copy full SHA for dec15d9

File tree

Expand file treeCollapse file tree

1 file changed

+16
-11
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-11
lines changed

‎http_cache/varnish.rst

Copy file name to clipboardExpand all lines: http_cache/varnish.rst
+16-11Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,29 @@ at least for some parts of the site, e.g. when using forms with
6767
and clear the session when it is no longer needed. Alternatively, you can look
6868
into :ref:`caching pages that contain CSRF protected forms <caching-pages-that-contain-csrf-protected-forms>`.
6969

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.
7782

7883
.. configuration-block::
7984

8085
.. code-block:: varnish4
8186
8287
sub vcl_recv {
83-
// Remove all cookies except the session ID.
88+
// Remove all cookies except for essential ones.
8489
if (req.http.Cookie) {
8590
set req.http.Cookie = ";" + req.http.Cookie;
8691
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=");
8893
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
8994
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
9095
@@ -98,11 +103,11 @@ configuration of PHP, your session cookie has the name ``PHPSESSID``:
98103
.. code-block:: varnish3
99104
100105
sub vcl_recv {
101-
// Remove all cookies except the session ID.
106+
// Remove all cookies except for essential ones.
102107
if (req.http.Cookie) {
103108
set req.http.Cookie = ";" + req.http.Cookie;
104109
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=");
106111
set req.http.Cookie = regsuball(req.http.Cookie, ";[^ ][^;]*", "");
107112
set req.http.Cookie = regsuball(req.http.Cookie, "^[; ]+|[; ]+$", "");
108113

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.