ACC-29Required
End sessions when access changes
End every other session when the password changes or a factor is removed. End every session when the account is disabled, deleted or locked after a "This wasn't me" report. Every revocation takes effect on every server within 60 seconds. This is the one home of that limit, for sign-outs, removed roles, removed members and directory removals too.
How to do it
Put the session cleanup in the same function and transaction as the change, so no code path forgets it. Sixty seconds is short enough to stop a stolen session and long enough for a cache across servers. Access tokens that live longer, as verify every token allows, need a check on each request against a revocation list or a "valid after" time. Keep the current session after a password change, because the person just proved who they are. A password reset already ends other sessions, as make password resets safe says. Removal from one organisation ends access there only, as remove access when someone leaves says.
Examples
JavaScript example
export async function changePassword(db, userId, currentSessionId, newHash) {
await db.tx(async tx => {
await tx.none('UPDATE users SET password_hash = $1 WHERE id = $2', [newHash, userId]);
await tx.none('DELETE FROM sessions WHERE user_id = $1 AND id <> $2', [userId, currentSessionId]);
});
}
Python example
def change_password(conn, user_id: str, current_session_id: str, new_hash: str) -> None:
with conn.transaction():
conn.execute("UPDATE users SET password_hash = %s WHERE id = %s", (new_hash, user_id))
conn.execute("DELETE FROM sessions WHERE user_id = %s AND id <> %s", (user_id, current_session_id))
How to check
Sign in from two browsers and change the password in the first. The second is signed out and the first stays in. Disable the test account as an admin, and the first is signed out too. Each sign-out lands within 60 seconds, for cookie sessions and for access tokens alike.
Sources
Related rules
- API-70 Check access when the connection opens and while it lasts in API design
- ACC-69 Make sign-in and reset links single-use and short-lived in Accounts and identity
- ACC-28 Let people sign out of one device or all of them in Accounts and identity
- APS-12 Verify every token in Application security
- ACC-46 Remove access when someone leaves in Accounts and identity
- ACC-38 Apply removed roles within the revocation limit in Accounts and identity
- ACC-61 Remove access when the directory says so in Accounts and identity
- AGT-9 Let users revoke one agent without the others in Agents as users
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/end-sessions-on-change">Agent Wranglers accounts and identity playbook</a>. In code you write, add a comment next to it with the same link.