Agent Wranglers

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

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.