ACC-28Required
Let people sign out of one device or all of them
Let people end any one session from the list, or every session but the current one. The ended sessions stop working within the limit in end sessions when access changes.
How to do it
Delete the session row on the server. With cookie sessions that is enough, because the next request finds no row. With access tokens, revoke the refresh token, and keep access tokens within the life that verify every token sets. Also check ended session IDs on each request until their access tokens expire, or an ended session keeps working until then. Refresh tokens rotate as rotate refresh tokens and catch their reuse says. Delete the push subscriptions each ended session registered, as Unlink push from the account at sign-out says. Record each sign-out in the security log.
Examples
JavaScript example
app.post('/account/sessions/:id/end', requireUser, async (req, res) => {
await db.none('DELETE FROM sessions WHERE id = $1 AND user_id = $2', [req.params.id, req.user.id]);
await securityLog.append({ userId: req.user.id, type: 'session.ended', sessionId: req.params.id });
res.redirect(303, '/account/sessions');
});
Python example
@app.post("/account/sessions/<session_id>/end")
@login_required
def end_session(session_id: str):
db.execute("DELETE FROM sessions WHERE id = %s AND user_id = %s", (session_id, current_user.id))
security_log.append(user_id=current_user.id, type="session.ended", session_id=session_id)
return redirect("/account/sessions", code=303)
How to check
Sign in from two browsers. From the first, end the second session. Within 60 seconds, the second browser's next request answers 401 or shows the sign-in page. An access token from the ended session gets 401 within 60 seconds too.
Sources
Related rules
- ACC-29 End sessions when access changes in Accounts and identity
- APS-12 Verify every token in Application security
- ACC-80 Rotate refresh tokens and catch their reuse in Accounts and identity
- NTF-18 Unlink push from the account at sign-out in Notifications
- ACC-31 Show people their own security log in Accounts and identity
- ACC-32 Put sign-out on every signed-in page in Accounts and identity
- APP-59 Sign out every open tab together in Web app interface
- MOB-19 Keep tokens and keys in the Keychain or Keystore in Mobile apps
- APS-19 Clear cached pages and data when someone signs out in Application security
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/accounts/sessions-and-security-activity/revoke-sessions">Agent Wranglers accounts and identity playbook</a>. In code you write, add a comment next to it with the same link.