{"action":"created","comment":{"url":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/22434107","id":22434107,"diff_hunk":"@@ -60,6 +60,54 @@ If the ``X-Forwarded-Port`` header is not set correctly, Symfony will append\n the port where the PHP application is running when generating absolute URLs,\n e.g. ``http://example.com:8080/my/path``.\n \n+Cookies and Caching\n+-------------------\n+\n+By default, a sane caching proxy does not cache anything when a request is sent\n+with :ref:`cookies or a basic authentication header<http-cache-introduction>`.\n+This is because the content of the page is supposed to depend on the cookie\n+value or authentication header.\n+\n+If you know for sure that the backend never uses sessions or basic\n+authentication, have varnish remove the corresponding header from requests to\n+prevent clients from bypassing the cache. In practice, you will need sessions\n+at least for some parts of the site, e.g. when using forms with\n+:ref:`CSRF Protection <forms-csrf>`. In this situation, make sure to only\n+start a session when actually needed, and clear the session when it is no\n+longer needed.\n+\n+.. todo link \"CSRF Protection\" to https://github.com/symfony/symfony-docs/pull/4141\n+.. todo link \"only start a session when actually needed\" to cookbook/session/avoid_session_start once https://github.com/symfony/symfony-docs/pull/4661 is merged\n+\n+Cookies created in Javascript and used only in the frontend, e.g. when using\n+Google analytics are nonetheless sent to the server. These cookies are not\n+relevant for the backend and should not affect the caching decision. Configure\n+your Varnish cache to `clean the cookies header`_. Unless you changed the\n+default configuration of PHP, your session cookie has the name PHPSESSID:\n+\n+.. code-block:: varnish4\n+\n+    sub vcl_recv {\n+        if (req.http.Cookie) {\n+            set req.http.Cookie = \";\" + req.http.Cookie;\n+            set req.http.Cookie = regsuball(req.http.Cookie, \"; +\", \";\");\n+            set req.http.Cookie = regsuball(req.http.Cookie, \";(PHPSESSID)=\", \"; \\1=\");\n+            set req.http.Cookie = regsuball(req.http.Cookie, \";[^ ][^;]*\", \"\");\n+            set req.http.Cookie = regsuball(req.http.Cookie, \"^[; ]+|[; ]+$\", \"\");\n+\n+            if (req.http.Cookie == \"\") {\n+                remove req.http.Cookie;\n+            }\n+        }\n+    }","path":"cookbook/cache/varnish.rst","position":43,"original_position":43,"commit_id":"893d7f4ccca1db412ca4334e9432c8a32d685ade","original_commit_id":"893d7f4ccca1db412ca4334e9432c8a32d685ade","user":{"login":"weaverryan","id":121003,"avatar_url":"https://avatars.githubusercontent.com/u/121003?v=3","gravatar_id":"","url":"https://api.github.com/users/weaverryan","html_url":"https://github.com/weaverryan","followers_url":"https://api.github.com/users/weaverryan/followers","following_url":"https://api.github.com/users/weaverryan/following{/other_user}","gists_url":"https://api.github.com/users/weaverryan/gists{/gist_id}","starred_url":"https://api.github.com/users/weaverryan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weaverryan/subscriptions","organizations_url":"https://api.github.com/users/weaverryan/orgs","repos_url":"https://api.github.com/users/weaverryan/repos","events_url":"https://api.github.com/users/weaverryan/events{/privacy}","received_events_url":"https://api.github.com/users/weaverryan/received_events","type":"User","site_admin":false},"body":"So what's the result of this? Is this removing the `PHPSESSID` cookie only before the request is made to the backend? If so, will this now mean that all the pages on my site cannot start a session (whether they're being cached or not?).\r\n\r\nThanks - I'm asking stupid questions because I'm not a pro on this, and I know we are very close to making this very easy and useful :).","created_at":"2015-01-03T19:16:08Z","updated_at":"2015-01-03T19:16:08Z","html_url":"https://github.com/symfony/symfony-docs/pull/4628#discussion_r22434107","pull_request_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4628","_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/22434107"},"html":{"href":"https://github.com/symfony/symfony-docs/pull/4628#discussion_r22434107"},"pull_request":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4628"}}},"pull_request":{"url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4628","id":25903476,"html_url":"https://github.com/symfony/symfony-docs/pull/4628","diff_url":"https://github.com/symfony/symfony-docs/pull/4628.diff","patch_url":"https://github.com/symfony/symfony-docs/pull/4628.patch","issue_url":"https://api.github.com/repos/symfony/symfony-docs/issues/4628","number":4628,"state":"open","locked":false,"title":"Varnish cookbook session cookie handling","user":{"login":"dbu","id":76576,"avatar_url":"https://avatars.githubusercontent.com/u/76576?v=3","gravatar_id":"","url":"https://api.github.com/users/dbu","html_url":"https://github.com/dbu","followers_url":"https://api.github.com/users/dbu/followers","following_url":"https://api.github.com/users/dbu/following{/other_user}","gists_url":"https://api.github.com/users/dbu/gists{/gist_id}","starred_url":"https://api.github.com/users/dbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbu/subscriptions","organizations_url":"https://api.github.com/users/dbu/orgs","repos_url":"https://api.github.com/users/dbu/repos","events_url":"https://api.github.com/users/dbu/events{/privacy}","received_events_url":"https://api.github.com/users/dbu/received_events","type":"User","site_admin":false},"body":"| Q             | A\r\n| ------------- | ---\r\n| Doc fix?      | yes\r\n| New docs?     | no\r\n| Applies to    | all\r\n| Fixed tickets | #3881\r\n\r\nThis builds on top of #4627 but i wanted to keep it separate as there are open questions in here.","created_at":"2014-12-11T14:34:21Z","updated_at":"2015-01-03T19:16:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"b21a2546a4c9769a25d36bc8dfca8095b4d0a68d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4628/commits","review_comments_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/4628/comments","review_comment_url":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/{number}","comments_url":"https://api.github.com/repos/symfony/symfony-docs/issues/4628/comments","statuses_url":"https://api.github.com/repos/symfony/symfony-docs/statuses/893d7f4ccca1db412ca4334e9432c8a32d685ade","head":{"label":"dbu:varnish-cookbook-session-cookie-handling","ref":"varnish-cookbook-session-cookie-handling","sha":"893d7f4ccca1db412ca4334e9432c8a32d685ade","user":{"login":"dbu","id":76576,"avatar_url":"https://avatars.githubusercontent.com/u/76576?v=3","gravatar_id":"","url":"https://api.github.com/users/dbu","html_url":"https://github.com/dbu","followers_url":"https://api.github.com/users/dbu/followers","following_url":"https://api.github.com/users/dbu/following{/other_user}","gists_url":"https://api.github.com/users/dbu/gists{/gist_id}","starred_url":"https://api.github.com/users/dbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbu/subscriptions","organizations_url":"https://api.github.com/users/dbu/orgs","repos_url":"https://api.github.com/users/dbu/repos","events_url":"https://api.github.com/users/dbu/events{/privacy}","received_events_url":"https://api.github.com/users/dbu/received_events","type":"User","site_admin":false},"repo":{"id":6651081,"name":"symfony-docs","full_name":"dbu/symfony-docs","owner":{"login":"dbu","id":76576,"avatar_url":"https://avatars.githubusercontent.com/u/76576?v=3","gravatar_id":"","url":"https://api.github.com/users/dbu","html_url":"https://github.com/dbu","followers_url":"https://api.github.com/users/dbu/followers","following_url":"https://api.github.com/users/dbu/following{/other_user}","gists_url":"https://api.github.com/users/dbu/gists{/gist_id}","starred_url":"https://api.github.com/users/dbu/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dbu/subscriptions","organizations_url":"https://api.github.com/users/dbu/orgs","repos_url":"https://api.github.com/users/dbu/repos","events_url":"https://api.github.com/users/dbu/events{/privacy}","received_events_url":"https://api.github.com/users/dbu/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dbu/symfony-docs","description":"The Symfony2 documentation","fork":true,"url":"https://api.github.com/repos/dbu/symfony-docs","forks_url":"https://api.github.com/repos/dbu/symfony-docs/forks","keys_url":"https://api.github.com/repos/dbu/symfony-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dbu/symfony-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dbu/symfony-docs/teams","hooks_url":"https://api.github.com/repos/dbu/symfony-docs/hooks","issue_events_url":"https://api.github.com/repos/dbu/symfony-docs/issues/events{/number}","events_url":"https://api.github.com/repos/dbu/symfony-docs/events","assignees_url":"https://api.github.com/repos/dbu/symfony-docs/assignees{/user}","branches_url":"https://api.github.com/repos/dbu/symfony-docs/branches{/branch}","tags_url":"https://api.github.com/repos/dbu/symfony-docs/tags","blobs_url":"https://api.github.com/repos/dbu/symfony-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dbu/symfony-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dbu/symfony-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/dbu/symfony-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dbu/symfony-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/dbu/symfony-docs/languages","stargazers_url":"https://api.github.com/repos/dbu/symfony-docs/stargazers","contributors_url":"https://api.github.com/repos/dbu/symfony-docs/contributors","subscribers_url":"https://api.github.com/repos/dbu/symfony-docs/subscribers","subscription_url":"https://api.github.com/repos/dbu/symfony-docs/subscription","commits_url":"https://api.github.com/repos/dbu/symfony-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/dbu/symfony-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/dbu/symfony-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/dbu/symfony-docs/issues/comments/{number}","contents_url":"https://api.github.com/repos/dbu/symfony-docs/contents/{+path}","compare_url":"https://api.github.com/repos/dbu/symfony-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dbu/symfony-docs/merges","archive_url":"https://api.github.com/repos/dbu/symfony-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dbu/symfony-docs/downloads","issues_url":"https://api.github.com/repos/dbu/symfony-docs/issues{/number}","pulls_url":"https://api.github.com/repos/dbu/symfony-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/dbu/symfony-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/dbu/symfony-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dbu/symfony-docs/labels{/name}","releases_url":"https://api.github.com/repos/dbu/symfony-docs/releases{/id}","created_at":"2012-11-12T09:34:52Z","updated_at":"2014-10-08T20:19:11Z","pushed_at":"2015-01-03T18:30:54Z","git_url":"git://github.com/dbu/symfony-docs.git","ssh_url":"git@github.com:dbu/symfony-docs.git","clone_url":"https://github.com/dbu/symfony-docs.git","svn_url":"https://github.com/dbu/symfony-docs","homepage":"http://symfony.com/doc/current/","size":23494,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"symfony:2.3","ref":"2.3","sha":"c5e409b70060405732b2251ae92e0278fd5f5e3d","user":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"repo":{"id":521583,"name":"symfony-docs","full_name":"symfony/symfony-docs","owner":{"login":"symfony","id":143937,"avatar_url":"https://avatars.githubusercontent.com/u/143937?v=3","gravatar_id":"","url":"https://api.github.com/users/symfony","html_url":"https://github.com/symfony","followers_url":"https://api.github.com/users/symfony/followers","following_url":"https://api.github.com/users/symfony/following{/other_user}","gists_url":"https://api.github.com/users/symfony/gists{/gist_id}","starred_url":"https://api.github.com/users/symfony/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/symfony/subscriptions","organizations_url":"https://api.github.com/users/symfony/orgs","repos_url":"https://api.github.com/users/symfony/repos","events_url":"https://api.github.com/users/symfony/events{/privacy}","received_events_url":"https://api.github.com/users/symfony/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/symfony/symfony-docs","description":"The Symfony2 documentation","fork":false,"url":"https://api.github.com/repos/symfony/symfony-docs","forks_url":"https://api.github.com/repos/symfony/symfony-docs/forks","keys_url":"https://api.github.com/repos/symfony/symfony-docs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/symfony/symfony-docs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/symfony/symfony-docs/teams","hooks_url":"https://api.github.com/repos/symfony/symfony-docs/hooks","issue_events_url":"https://api.github.com/repos/symfony/symfony-docs/issues/events{/number}","events_url":"https://api.github.com/repos/symfony/symfony-docs/events","assignees_url":"https://api.github.com/repos/symfony/symfony-docs/assignees{/user}","branches_url":"https://api.github.com/repos/symfony/symfony-docs/branches{/branch}","tags_url":"https://api.github.com/repos/symfony/symfony-docs/tags","blobs_url":"https://api.github.com/repos/symfony/symfony-docs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/symfony/symfony-docs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/symfony/symfony-docs/git/refs{/sha}","trees_url":"https://api.github.com/repos/symfony/symfony-docs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/symfony/symfony-docs/statuses/{sha}","languages_url":"https://api.github.com/repos/symfony/symfony-docs/languages","stargazers_url":"https://api.github.com/repos/symfony/symfony-docs/stargazers","contributors_url":"https://api.github.com/repos/symfony/symfony-docs/contributors","subscribers_url":"https://api.github.com/repos/symfony/symfony-docs/subscribers","subscription_url":"https://api.github.com/repos/symfony/symfony-docs/subscription","commits_url":"https://api.github.com/repos/symfony/symfony-docs/commits{/sha}","git_commits_url":"https://api.github.com/repos/symfony/symfony-docs/git/commits{/sha}","comments_url":"https://api.github.com/repos/symfony/symfony-docs/comments{/number}","issue_comment_url":"https://api.github.com/repos/symfony/symfony-docs/issues/comments/{number}","contents_url":"https://api.github.com/repos/symfony/symfony-docs/contents/{+path}","compare_url":"https://api.github.com/repos/symfony/symfony-docs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/symfony/symfony-docs/merges","archive_url":"https://api.github.com/repos/symfony/symfony-docs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/symfony/symfony-docs/downloads","issues_url":"https://api.github.com/repos/symfony/symfony-docs/issues{/number}","pulls_url":"https://api.github.com/repos/symfony/symfony-docs/pulls{/number}","milestones_url":"https://api.github.com/repos/symfony/symfony-docs/milestones{/number}","notifications_url":"https://api.github.com/repos/symfony/symfony-docs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/symfony/symfony-docs/labels{/name}","releases_url":"https://api.github.com/repos/symfony/symfony-docs/releases{/id}","created_at":"2010-02-17T08:43:51Z","updated_at":"2015-01-02T23:05:10Z","pushed_at":"2015-01-03T19:05:22Z","git_url":"git://github.com/symfony/symfony-docs.git","ssh_url":"git@github.com:symfony/symfony-docs.git","clone_url":"https://github.com/symfony/symfony-docs.git","svn_url":"https://github.com/symfony/symfony-docs","homepage":"http://symfony.com/doc/current/","size":50681,"stargazers_count":944,"watchers_count":944,"language":"Python","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":1627,"mirror_url":null,"open_issues_count":251,"forks":1627,"open_issues":251,"watchers":944,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4628"},"html":{"href":"https://github.com/symfony/symfony-docs/pull/4628"},"issue":{"href":"https://api.github.com/repos/symfony/symfony-docs/issues/4628"},"comments":{"href":"https://api.github.com/repos/symfony/symfony-docs/issues/4628/comments"},"review_comments":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4628/comments"},"review_comment":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/symfony/symfony-docs/pulls/4628/commits"},"statuses":{"href":"https://api.github.com/repos/symfony/symfony-docs/statuses/893d7f4ccca1db412ca4334e9432c8a32d685ade"}}}}