Security: sessions survive account deletion, demotion and password change (no per-user revocation, admin flag is a 12h snapshot) #839

Closed
opened 2026-10-03 16:36:28 +00:00 by Cordy · 3 comments
Owner

Found in the #533 QA pass (2026-10-03, local build of main @ v0.6.317). Companion to #838 (credential cache).

What happens (reproduced)

  • Sessions are in-memory snapshots {User, issued, expires} with a 12 h TTL (internal/auth/session.go). PasswordLogin.Authenticate returns the stored User on any valid cookie (internal/auth/login.go ~23-29). There is Revoke(token) but no revoke-by-user.
  • Deleted local account: its open session still answers GET /api/v1/me (200) and lists files (200). This lasts up to 12 h or until restart. The handbook promises that deleting freezes everything; the person's own session defeats that.
  • Demoted admin: the session keeps Admin:true, so /api/v1/admin/* still answers 200. adminFlag.Authenticate can only add admin (union), never remove it (internal/auth/adminflag.go ~34-52).
  • Password reset/change: every other session of that user stays signed in.
  • Directory accounts are very likely the same (OIDC sessions are the same snapshot type; dashboard "Remove admin" goes through the runtime admin lookup, which also can only add). Not exercised without an IdP.
  • Users & access → "Signed in now" also counts the deleted account's leftover session (see the polish issue).

Research

  • OWASP (Session Management): after a privilege change (role change, password change, account recovery), previous sessions must not keep the old privilege. Authorization has to be enforced per request, not cached in the session.
  • The same bug class elsewhere:
    • LAMB #256: a disabled user keeps full privileges, including disabling the admin who disabled them, until logout.
    • OSV GHSA-4vxv-4xq4-p84h: a deleted user remains logged in indefinitely, because state is checked only at login.
    • OrangeHRM CVE-2025-66289: sessions valid after disable or password change.
    • MongoDB CVE-2019-2386: a session of a deleted user is conflated with a new account reusing the name. This matters for Cairn, because re-creating a local account with the same name "unfreezes everything as it was" (handbook). A stale session must never attach to the new account.
  • What competitors do. Nextcloud keeps sessions and tokens in a table keyed by user. Disabling or deleting a user kills them, and changing your password offers "log out other devices". It also learned to scope this to the one user (server #17166, where everyone got logged out).
  • What worked best in practice. Per-request re-validation of account state and role is cheap when the source is in memory (LocalStore, AdminStore, liveness oracle cache). That beats trying to find and kill every session on every change. Do both: re-validate on every request (defence in depth), and revoke on the explicit events (clean UX, and "Signed in now" becomes truthful).

Plan

  1. Sessions.RevokeUser(username) drops every session of that user.
    • Called on local delete, password reset, own password change (keep the current session, or re-issue it), demote, and directory "Remove admin".
  2. Bind each session to its account.
    • A session records the account's generation, shared with #838.
    • Lookup rejects the session if the account no longer exists or its generation changed.
    • This kills the MongoDB-style "re-created name inherits the old session" bug.
  3. Per-request admin.
    • The session stores identity only.
    • Admin is recomputed on each request from config admins, AdminStore, local admin flag and admin groups, in one function shared with adminFlag.
    • The union-only logic then becomes a true current value, so demotion takes effect on the next request.
  4. Directory accounts.
    • The OIDC/LDAP session carries the groups resolved at sign-in. For group-based admin, re-resolve periodically (same TTL idea as #838 for LDAP).
    • For OIDC, either re-check on refresh or cap the session by the ID token lifetime. Document which one.

Tests (red first)

  • delete → that user's session 401, others unaffected;
  • demote → the next admin request 403 on the same session;
  • reset → other sessions 401 and the resetting admin unaffected;
  • own change → other sessions 401, current session keeps working;
  • delete then re-create with the same name → the old cookie stays 401;
  • "Signed in now" no longer counts revoked sessions.

Decision for Nikola

On your own password change: sign out the other devices automatically (proposed, OWASP default), or ask with a checkbox, as Nextcloud does?

Refs:

Found in the #533 QA pass (2026-10-03, local build of main @ v0.6.317). Companion to #838 (credential cache). ## What happens (reproduced) - Sessions are in-memory snapshots `{User, issued, expires}` with a 12 h TTL (internal/auth/session.go). `PasswordLogin.Authenticate` returns the stored `User` on any valid cookie (internal/auth/login.go ~23-29). There is `Revoke(token)` but **no revoke-by-user**. - **Deleted local account:** its open session still answers `GET /api/v1/me` (200) and lists files (200). This lasts up to 12 h or until restart. The handbook promises that deleting freezes everything; the person's own session defeats that. - **Demoted admin:** the session keeps `Admin:true`, so `/api/v1/admin/*` still answers 200. `adminFlag.Authenticate` can only *add* admin (union), never remove it (internal/auth/adminflag.go ~34-52). - **Password reset/change:** every other session of that user stays signed in. - **Directory accounts are very likely the same** (OIDC sessions are the same snapshot type; dashboard "Remove admin" goes through the runtime admin lookup, which also can only add). Not exercised without an IdP. - Users & access → "Signed in now" also counts the deleted account's leftover session (see the polish issue). ## Research - **OWASP** (Session Management): after a privilege change (role change, password change, account recovery), previous sessions must not keep the old privilege. Authorization has to be enforced per request, not cached in the session. - **The same bug class elsewhere:** - LAMB #256: a disabled user keeps full privileges, including disabling the admin who disabled them, until logout. - OSV GHSA-4vxv-4xq4-p84h: a deleted user remains logged in indefinitely, because state is checked only at login. - OrangeHRM CVE-2025-66289: sessions valid after disable or password change. - MongoDB CVE-2019-2386: a session of a deleted user is conflated with a **new account reusing the name**. This matters for Cairn, because re-creating a local account with the same name "unfreezes everything as it was" (handbook). A stale session must never attach to the new account. - **What competitors do.** Nextcloud keeps sessions and tokens in a table keyed by user. Disabling or deleting a user kills them, and changing your password offers "log out other devices". It also learned to scope this to the one user (server #17166, where everyone got logged out). - **What worked best in practice.** Per-request re-validation of account state and role is cheap when the source is in memory (LocalStore, AdminStore, liveness oracle cache). That beats trying to find and kill every session on every change. Do both: re-validate on every request (defence in depth), and revoke on the explicit events (clean UX, and "Signed in now" becomes truthful). ## Plan 1. **`Sessions.RevokeUser(username)`** drops every session of that user. - Called on local delete, password reset, own password change (keep the *current* session, or re-issue it), demote, and directory "Remove admin". 2. **Bind each session to its account.** - A session records the account's **generation**, shared with #838. - `Lookup` rejects the session if the account no longer exists or its generation changed. - This kills the MongoDB-style "re-created name inherits the old session" bug. 3. **Per-request admin.** - The session stores identity only. - `Admin` is recomputed on each request from config admins, AdminStore, local admin flag and admin groups, in one function shared with `adminFlag`. - The union-only logic then becomes a true current value, so demotion takes effect on the next request. 4. **Directory accounts.** - The OIDC/LDAP session carries the groups resolved at sign-in. For group-based admin, re-resolve periodically (same TTL idea as #838 for LDAP). - For OIDC, either re-check on refresh or cap the session by the ID token lifetime. Document which one. ### Tests (red first) - delete → that user's session 401, others unaffected; - demote → the next admin request 403 on the same session; - reset → other sessions 401 and the resetting admin unaffected; - own change → other sessions 401, current session keeps working; - delete then re-create with the same name → the old cookie stays 401; - "Signed in now" no longer counts revoked sessions. ### Decision for Nikola On your own password change: sign out the other devices automatically (proposed, OWASP default), or ask with a checkbox, as Nextcloud does? Refs: - https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html - https://github.com/Lamb-Project/lamb/issues/256 - https://osv.dev/vulnerability/GHSA-4vxv-4xq4-p84h - https://nvd.nist.gov/vuln/detail/CVE-2025-66289 - https://nvd.nist.gov/vuln/detail/CVE-2019-2386 - https://github.com/nextcloud/server/issues/17166
Author
Owner

Process note (Nikola, 2026-10-03): the "Decision for Nikola" above (whether changing your own password signs out your other devices automatically or asks) gets asked when this issue is worked on. Work starts now, together with #838.

Process note (Nikola, 2026-10-03): the "Decision for Nikola" above (whether changing your own password signs out your other devices automatically or asks) gets asked when this issue is worked on. Work starts now, together with #838.
Author
Owner

Decisions (Nikola, 2026-10-03):

  • Own password change: every other session of that person is signed out automatically. The current session stays signed in, and app passwords keep working.
  • OIDC group changes: Cairn re-checks the IdP periodically (account and groups). Removal from the admin group in Keycloak therefore takes effect within minutes, not at the end of the up-to-12h session.
**Decisions (Nikola, 2026-10-03):** - **Own password change:** every other session of that person is **signed out automatically**. The current session stays signed in, and app passwords keep working. - **OIDC group changes:** Cairn **re-checks the IdP periodically** (account and groups). Removal from the admin group in Keycloak therefore takes effect within minutes, not at the end of the up-to-12h session.
Cordy closed this issue 2026-10-06 17:00:01 +00:00
Author
Owner

Dogfood check of back-channel logout, v0.6.318, cairn-enc, 2026-10-06

Setup: Keycloak realm cordyceps, client cairn, Backchannel logout URL http://cairn-enc.cairn.svc.cluster.local/auth/backchannel-logout, "session required" on. The setting was made by hand on the live realm; it's also in homelab-config k3s/keycloak/realm-configmap.yaml (308a89b) for rebuilds.

Test: nikola-test signed in to files.c0rdyceps.ch, and an admin then ended the session from the Keycloak admin console (Users › nikola-test › Sessions):

21:53:25.283 POST /auth/backchannel-logout 200  remote=10.42.1.148 (Keycloak pod)
21:53:27.041 GET  /api/v1/notifications    401  (same browser, next poll)
21:53:28.065 GET  /login                   200

The session ended within about 2 seconds of the Keycloak sign-out, without any action in Cairn. Pass.

An earlier run used Cairn's own Sign out. That also ends the Keycloak session, and Keycloak's back-channel call arrived afterwards and was accepted with 200.

Limitation: files-bao shares the cairn client, and a client takes only one back-channel URL, so files-bao isn't covered until it gets its own Keycloak client.

**Dogfood check of back-channel logout, v0.6.318, cairn-enc, 2026-10-06** Setup: Keycloak realm `cordyceps`, client `cairn`, Backchannel logout URL `http://cairn-enc.cairn.svc.cluster.local/auth/backchannel-logout`, "session required" on. The setting was made by hand on the live realm; it's also in homelab-config `k3s/keycloak/realm-configmap.yaml` (308a89b) for rebuilds. Test: nikola-test signed in to files.c0rdyceps.ch, and an admin then ended the session from the Keycloak admin console (Users › nikola-test › Sessions): ``` 21:53:25.283 POST /auth/backchannel-logout 200 remote=10.42.1.148 (Keycloak pod) 21:53:27.041 GET /api/v1/notifications 401 (same browser, next poll) 21:53:28.065 GET /login 200 ``` The session ended within about 2 seconds of the Keycloak sign-out, without any action in Cairn. **Pass.** An earlier run used Cairn's own Sign out. That also ends the Keycloak session, and Keycloak's back-channel call arrived afterwards and was accepted with 200. Limitation: files-bao shares the `cairn` client, and a client takes only one back-channel URL, so files-bao isn't covered until it gets its own Keycloak client.
Sign in to join this conversation.
No labels
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: Cordy/Cairn#839
No description provided.