In a discussion titled “How to sync logout with SSO or Browser session?” under the Support category, peteratkins describes a security concern where multiple users on the same machine can inherit the previous user’s Discourse session due to persistent cookies, even after browser closure. He notes that a 2016 fix allowing cookies to expire with browser closure was reverted, leaving sessions active for at least one hour. Falco responds that this is not considered a security flaw and suggests two workarounds: porting the reverted code into a custom plugin or integrating SSO logout to trigger Discourse session termination via API. peteratkins expresses disappointment over the reverted code and requests guidance on Discourse API calls to terminate sessions. Falco provides a reference to the logout API endpoint: http(s)://forum.example.com/admin/users/{user_id}/log_out, noting that {user_id} must match the Discourse user ID, not the external system’s ID. The conversation highlights the need for custom integration to enforce session hygiene in shared-workstation environments.
User one starts a browser and connects to the Forum using SSO, works for a while and then closes browser.
User two starts a browser on the same machine and logs into the Forum again using SSO. The process takes him through the full login with his credentials but when he enters the forum he is logged in as User one.
Discourse will allow the session timeout to be set to a minimum of one hour. This means that the user can return to the PC within one hour and simply log in and gain the identity of the previous user from cookies.
There was a fix back in 2016 to allow the cookies to die when the browser was closed but this was reverted.
This makes the software very insecure in an environment where multiple people use the same workstation if the browser has not been configured to work in private mode.
You can check the code from the above commit, that was reverted, and port it to a plugin to suit your needs.
You can also code a logout integration in your SSO system, so when a user log outs it calls Discourse to terminate all existing sessions of the same user.