{"action":"created","issue":{"url":"https://api.github.com/repos/bolt/bolt/issues/5658","repository_url":"https://api.github.com/repos/bolt/bolt","labels_url":"https://api.github.com/repos/bolt/bolt/issues/5658/labels{/name}","comments_url":"https://api.github.com/repos/bolt/bolt/issues/5658/comments","events_url":"https://api.github.com/repos/bolt/bolt/issues/5658/events","html_url":"https://github.com/bolt/bolt/issues/5658","id":170105885,"number":5658,"title":"[Bug] Memcache Session Management broken","user":{"login":"ToBe998","id":12497310,"avatar_url":"https://avatars.githubusercontent.com/u/12497310?v=3","gravatar_id":"","url":"https://api.github.com/users/ToBe998","html_url":"https://github.com/ToBe998","followers_url":"https://api.github.com/users/ToBe998/followers","following_url":"https://api.github.com/users/ToBe998/following{/other_user}","gists_url":"https://api.github.com/users/ToBe998/gists{/gist_id}","starred_url":"https://api.github.com/users/ToBe998/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ToBe998/subscriptions","organizations_url":"https://api.github.com/users/ToBe998/orgs","repos_url":"https://api.github.com/users/ToBe998/repos","events_url":"https://api.github.com/users/ToBe998/events{/privacy}","received_events_url":"https://api.github.com/users/ToBe998/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":{"login":"CarsonF","id":932566,"avatar_url":"https://avatars.githubusercontent.com/u/932566?v=3","gravatar_id":"","url":"https://api.github.com/users/CarsonF","html_url":"https://github.com/CarsonF","followers_url":"https://api.github.com/users/CarsonF/followers","following_url":"https://api.github.com/users/CarsonF/following{/other_user}","gists_url":"https://api.github.com/users/CarsonF/gists{/gist_id}","starred_url":"https://api.github.com/users/CarsonF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CarsonF/subscriptions","organizations_url":"https://api.github.com/users/CarsonF/orgs","repos_url":"https://api.github.com/users/CarsonF/repos","events_url":"https://api.github.com/users/CarsonF/events{/privacy}","received_events_url":"https://api.github.com/users/CarsonF/received_events","type":"User","site_admin":false},"assignees":[{"login":"CarsonF","id":932566,"avatar_url":"https://avatars.githubusercontent.com/u/932566?v=3","gravatar_id":"","url":"https://api.github.com/users/CarsonF","html_url":"https://github.com/CarsonF","followers_url":"https://api.github.com/users/CarsonF/followers","following_url":"https://api.github.com/users/CarsonF/following{/other_user}","gists_url":"https://api.github.com/users/CarsonF/gists{/gist_id}","starred_url":"https://api.github.com/users/CarsonF/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CarsonF/subscriptions","organizations_url":"https://api.github.com/users/CarsonF/orgs","repos_url":"https://api.github.com/users/CarsonF/repos","events_url":"https://api.github.com/users/CarsonF/events{/privacy}","received_events_url":"https://api.github.com/users/CarsonF/received_events","type":"User","site_admin":false}],"milestone":null,"comments":7,"created_at":"2016-08-09T08:09:49Z","updated_at":"2016-08-09T13:38:06Z","closed_at":null,"body":"The session management in Bolt 3+ currently has a design flaw that breaks sessions in a couple of situations.\r\n\r\nBolt has it's own session management that reads and writes directly to session storage and is not using the PHP native session storage like other applications (including silex and sf2 apps do). This leads to trouble when paired with the ability of Bolts SessionServiceProvider to parse and import PHPs session options.\r\nIf you do this, Bolt essentially uses the same session storage as PHP and conflicts with it. See this scenario:\r\n- PHP Session reads it's data , currently containing \"START\". This allways happens at \"session_start\", probably during application boot.\r\n- Bolt reads it's session data, still containing \"START\".\r\n- Bolt writes \"CHANGED\" to it's session (while not using PHPs session but writing to storage directly)\r\n- PHP Writes \"START\" to it's session at Script end automatically (It didnt get the change by bolt before)\r\n-> Session get's overwritten!\r\n\r\nThis happens for all session handlers, that create the same storage when used by Bolt *and* by PHP. The filesystem handler is safe as it uses different paths and filenames. I don't know about Redis, *but memcache will use same host and storage key* when used by Bolt and by the PHP session handler.\r\n\r\n**Suggested Solution**\r\n\r\n- **Bad but working** Disable the \"import from ini\" feature and provide an option to configure the memcache connection paths for Bolt inside it's own config. Then you could remove the settings from PHPs session handler and the two would no longer conflict. This solution would however still try to reinvent then wheel, provide it's own cookie mechanics and it has not lazy writes or script end handlers.\r\n\r\n- **Good Solution** Use the session manager as it is supposed to be used and common to almost all Silex/Sf2 Apps. You create your own handlers, but access to session data still happens through PHPs native session functions. Then the custom handler is registered via `session_set_save_handler `. This has no drawbacks on security (validation still happens, just on session data and not on the mechanism to load them. There is no loss of features as the official mechanism is fully compatible with your solution and is actually the one preferred by SF2. The Handlers provided by SF2 and used by Bolt directly are actually intended to be sued like this.\r\n\r\n**Reproduction**\r\nYou can reproduce this by configuring the same session storage for PHP and for Bolt. This is easiest with a memcache handler (They will use the same connection and storage keys automaticlly, hence the bug). But you can probably also use the filesystem handler if you set the path and filename mechanisms so Bolt will use the same files as PHP would.\r\n\r\nIn my case, you can see a Session Error message on Login. You have to logout before that though, as the conflicting sessions from Bolt and PHP sometimes make it look like you are logged in.\r\n\r\nYou can also see that your memcache server gets strange requests not routed through Bolts session management.\r\n\r\n**Counter Test**\r\nIf you hard code the connection string to memcache inside the SessionServiceProvider and then remove the session settings from PHP, the conflicts vanish and sessions work fine again."},"comment":{"url":"https://api.github.com/repos/bolt/bolt/issues/comments/238555199","html_url":"https://github.com/bolt/bolt/issues/5658#issuecomment-238555199","issue_url":"https://api.github.com/repos/bolt/bolt/issues/5658","id":238555199,"user":{"login":"ToBe998","id":12497310,"avatar_url":"https://avatars.githubusercontent.com/u/12497310?v=3","gravatar_id":"","url":"https://api.github.com/users/ToBe998","html_url":"https://github.com/ToBe998","followers_url":"https://api.github.com/users/ToBe998/followers","following_url":"https://api.github.com/users/ToBe998/following{/other_user}","gists_url":"https://api.github.com/users/ToBe998/gists{/gist_id}","starred_url":"https://api.github.com/users/ToBe998/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ToBe998/subscriptions","organizations_url":"https://api.github.com/users/ToBe998/orgs","repos_url":"https://api.github.com/users/ToBe998/repos","events_url":"https://api.github.com/users/ToBe998/events{/privacy}","received_events_url":"https://api.github.com/users/ToBe998/received_events","type":"User","site_admin":false},"created_at":"2016-08-09T13:38:06Z","updated_at":"2016-08-09T13:38:06Z","body":"Didnt test this, but if we add the following block to your `SessionServiceProvider->registerMemcacheHandler`, it should make memcachd work again, right?\r\n\r\n```\r\n$app['session.handler_factory.backing_memcached'] = $app->protect(\r\n            function ($connections) {\r\n                $memcached = new \\Memcached();\r\n\r\n                foreach ($connections as $conn) {\r\n                    $memcached->addServer(\r\n                        $conn['host'] ?: 'localhost',\r\n                        $conn['port'] ?: 11211\r\n                    );\r\n                }\r\n\r\n                return $memcached;\r\n            }\r\n        );\r\n```"}}
{"actor":{"display_login":"ToBe998"}}