Security: old password keeps working after reset/change (verified-credential cache never invalidated; LDAP cache has no expiry) #838

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

Found in the #533 QA pass (2026-10-03, local build of main @ v0.6.317). Reproduced deterministically.

What happens

  • auth.Local keeps verified map[username]sha256(password) (internal/auth/auth.go ~46-122). A cache hit returns success before argon2 runs.
  • Nothing ever clears it. LocalStore.SetPassword and LocalStore.Delete (internal/auth/localstore.go ~134-155) only touch the store.
  • Repro:
    1. Sign in with password A.
    2. An admin resets to B, or the user changes it via POST /api/v1/me/password.
    3. Sign in with A: 204. WebDAV Basic with A: 207.
    4. A keeps working until someone signs in with B (which overwrites the cache entry) or the process restarts.
  • Impact: resetting a leaked password does not lock the attacker out. On a quiet account the old password can live for days, and WebDAV clients keep presenting it.
  • The same pattern exists in LDAP, so far from reading the code only (internal/auth/ldapauth/ldap.go ~70-85). verified caches the credential fingerprint plus the resolved groups, with no TTL.
    • A password changed, or an account disabled, in AD/LDAP keeps working against Cairn until restart.
    • Group membership is frozen at first bind, so removal from an admin group in AD keeps the person admin in Cairn.
    • This hits Manuel's banking, cantonal and military scenario directly (centrally managed admins).
    • To be verified against Manuel's Mokapi AD.
  • App passwords already re-check liveness on a cache hit (apppassword.go ~189-228). That pattern is the model to follow.

Research

  • OWASP.
    • The Session Management cheat sheet says to invalidate or re-establish session state on any privilege change, explicitly including password changes and account recovery.
    • The Forgot Password cheat sheet says a reset should end existing sessions.
    • The cache here is a credential acceptor rather than a session, but it is the same failure: an authenticator that outlives the credential.
  • Recent advisories with the same root cause:
    • Flowise GHSA-x7rp-qj2h-ghgw, "Failure to invalidate existing sessions after password change";
    • OrangeHRM CVE-2025-66289, sessions valid after password change or disable.
    • These were rated and fixed as security bugs, not UX.
  • Nextcloud's experience.
    • It ties credential-derived tokens to the password and had to work out which ones survive a change. App passwords must survive (server #2581), browser sessions are invalidated.
    • One early regression logged out every user when one user changed a password (server #17166). So scope invalidation strictly to the affected user.
  • LDAP caches elsewhere. Many products cache LDAP binds for performance, which is why Cairn has one. The accepted practice is a short TTL (minutes) plus re-resolving groups. A permanent cache is the outlier.

Plan

  1. Local.
    • LocalStore gets a change hook. SetPassword, Delete and SetAdmin bump a per-user credential generation. Alternatively, Local subscribes and calls forget(username).
    • A Local.verified entry stores the generation it was verified under. A hit is valid only if the generation still matches.
    • This is simpler than callbacks and survives future store mutations.
  2. Config users (auth.users) can't change at runtime. No change needed, but the test documents it.
  3. LDAP.
    • Add a TTL to verifiedEntry (proposal: 5 minutes, configurable ldap.cacheTTL).
    • On expiry, re-bind and re-resolve groups.
    • Keep the dedupe limiter so Finder and Windows mount storms still collapse into one bind.
  4. App passwords are untouched (already correct). Add a regression test that a main-password change does not break them, following the Nextcloud #2581 lesson.

Tests (red first)

  • local reset → old password 401 on the form and on Basic, new password 204;
  • self-change → same;
  • delete → 401;
  • generation bump on one user does not affect another user's cache hit (Nextcloud #17166 lesson);
  • LDAP: with a fake directory, a cache entry expires after the TTL and a changed password or group membership is picked up;
  • app password survives a main-password change.

Decision for Nikola

The LDAP TTL default: 5 minutes is proposed. It trades directory load against how long a revoked AD password keeps working.

Refs:

Found in the #533 QA pass (2026-10-03, local build of main @ v0.6.317). Reproduced deterministically. ## What happens - `auth.Local` keeps `verified map[username]sha256(password)` (internal/auth/auth.go ~46-122). A cache hit returns success before argon2 runs. - Nothing ever clears it. `LocalStore.SetPassword` and `LocalStore.Delete` (internal/auth/localstore.go ~134-155) only touch the store. - Repro: 1. Sign in with password A. 2. An admin resets to B, or the user changes it via `POST /api/v1/me/password`. 3. Sign in with A: **204**. WebDAV Basic with A: **207**. 4. A keeps working until someone signs in with B (which overwrites the cache entry) or the process restarts. - Impact: resetting a leaked password does **not** lock the attacker out. On a quiet account the old password can live for days, and WebDAV clients keep presenting it. - **The same pattern exists in LDAP, so far from reading the code only** (internal/auth/ldapauth/ldap.go ~70-85). `verified` caches the credential fingerprint **plus the resolved groups**, with no TTL. - A password changed, or an account disabled, in AD/LDAP keeps working against Cairn until restart. - Group membership is frozen at first bind, so **removal from an admin group in AD keeps the person admin in Cairn**. - This hits Manuel's banking, cantonal and military scenario directly (centrally managed admins). - To be verified against Manuel's Mokapi AD. - App passwords already re-check liveness on a cache hit (`apppassword.go` ~189-228). That pattern is the model to follow. ## Research - **OWASP.** - The Session Management cheat sheet says to invalidate or re-establish session state on any privilege change, explicitly including password changes and account recovery. - The Forgot Password cheat sheet says a reset should end existing sessions. - The cache here is a credential acceptor rather than a session, but it is the same failure: an authenticator that outlives the credential. - **Recent advisories with the same root cause:** - Flowise GHSA-x7rp-qj2h-ghgw, "Failure to invalidate existing sessions after password change"; - OrangeHRM CVE-2025-66289, sessions valid after password change or disable. - These were rated and fixed as security bugs, not UX. - **Nextcloud's experience.** - It ties credential-derived tokens to the password and had to work out which ones survive a change. App passwords must survive (server #2581), browser sessions are invalidated. - One early regression logged out *every* user when *one* user changed a password (server #17166). So scope invalidation strictly to the affected user. - **LDAP caches elsewhere.** Many products cache LDAP binds for performance, which is why Cairn has one. The accepted practice is a short TTL (minutes) plus re-resolving groups. A permanent cache is the outlier. ## Plan 1. **Local.** - `LocalStore` gets a change hook. SetPassword, Delete and SetAdmin bump a per-user **credential generation**. Alternatively, `Local` subscribes and calls `forget(username)`. - A `Local.verified` entry stores the generation it was verified under. A hit is valid only if the generation still matches. - This is simpler than callbacks and survives future store mutations. 2. **Config users** (`auth.users`) can't change at runtime. No change needed, but the test documents it. 3. **LDAP.** - Add a TTL to `verifiedEntry` (proposal: 5 minutes, configurable `ldap.cacheTTL`). - On expiry, re-bind and re-resolve groups. - Keep the dedupe limiter so Finder and Windows mount storms still collapse into one bind. 4. **App passwords** are untouched (already correct). Add a regression test that a main-password change does not break them, following the Nextcloud #2581 lesson. ### Tests (red first) - local reset → old password 401 on the form and on Basic, new password 204; - self-change → same; - delete → 401; - generation bump on one user does not affect another user's cache hit (Nextcloud #17166 lesson); - LDAP: with a fake directory, a cache entry expires after the TTL and a changed password or group membership is picked up; - app password survives a main-password change. ### Decision for Nikola The LDAP TTL default: 5 minutes is proposed. It trades directory load against how long a revoked AD password keeps working. Refs: - https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html - https://cheatsheetseries.owasp.org/cheatsheets/Forgot_Password_Cheat_Sheet.html - https://github.com/FlowiseAI/Flowise/security/advisories/GHSA-x7rp-qj2h-ghgw - https://nvd.nist.gov/vuln/detail/CVE-2025-66289 - https://github.com/nextcloud/server/issues/2581 - https://github.com/nextcloud/server/issues/17166
Author
Owner

Process note (Nikola, 2026-10-03): the "Decision for Nikola" above (the LDAP cache TTL) gets asked when this issue is worked on, not before. Work starts now, together with #839.

Process note (Nikola, 2026-10-03): the "Decision for Nikola" above (the LDAP cache TTL) gets asked when this issue is worked on, not before. Work starts now, together with #839.
Author
Owner

LDAP part confirmed (2026-10-03). I ran a scratch test against Cairn's LDAP provider using the repo's own in-memory directory (fakeConn); the test was not committed. After one successful bind:

  1. The password is changed in the directory. The old password is still accepted.
  2. The user is removed from cn=cairn-admins. The groups returned are still [cairn-admins], so the person stays admin.
  3. The account is deleted in the directory. It is still accepted.

All three hold until Cairn restarts. This confirms the code reading at the provider level.

A real-protocol check against a running mock AD (Mokapi, as Manuel uses) is still to do. It needs Mokapi installed locally, which is pending Nikola's OK to download it.

**LDAP part confirmed (2026-10-03).** I ran a scratch test against Cairn's LDAP provider using the repo's own in-memory directory (`fakeConn`); the test was not committed. After one successful bind: 1. The password is changed in the directory. The **old password is still accepted**. 2. The user is removed from `cn=cairn-admins`. **The groups returned are still `[cairn-admins]`**, so the person stays admin. 3. The account is deleted in the directory. **It is still accepted.** All three hold until Cairn restarts. This confirms the code reading at the provider level. A real-protocol check against a running mock AD (Mokapi, as Manuel uses) is still to do. It needs Mokapi installed locally, which is pending Nikola's OK to download it.
Author
Owner

Decision (Nikola, 2026-10-03): the LDAP/AD verified-sign-in cache is trusted for 5 minutes, configurable. After that Cairn re-binds and re-resolves groups. Where the setting lives (config only, or also the admin dashboard) is still open; see the design discussion.

**Decision (Nikola, 2026-10-03):** the LDAP/AD verified-sign-in cache is trusted for **5 minutes, configurable**. After that Cairn re-binds and re-resolves groups. Where the setting lives (config only, or also the admin dashboard) is still open; see the design discussion.
Author
Owner

LDAP part confirmed over the real protocol (2026-10-03).

Setup:

  • Mokapi 0.52.0 serves the mock AD on ldap://127.0.0.1:3890. The LDIF is hot-reloaded on change, so "AD admin actions" are file edits.
  • A local Cairn build of main runs in auth.mode: ldap with adminGroups: ["cairn-admins"].
  • User anna has memberOf: cn=cairn-admins and a groupOfNames entry.
  • After each change, I checked the directory side with ldapsearch to prove the mock had changed.
Step Directory (ldapsearch) Cairn
T0: sign in accepts /api/v1/me admin=true, groups=[cairn-admins]; WebDAV 207
T1: password changed in AD old rejected, new accepted old password still accepted (API and WebDAV 207) until the new one was used once, which overwrote the cache entry
T2: removed from cairn-admins in AD memberOf count 0 admin=true, groups=[cairn-admins] (stale)
T3: account deleted in AD bind rejected, 0 entries still signs in, admin=true, WebDAV 207
T4: wrong password never cached rejected refused (correct)

Conclusion. A person disabled or removed from the admin group in AD keeps full admin access to Cairn over WebDAV and the API until Cairn restarts. This is the exact scenario from Manuel's banking, cantonal and military requirement. It confirms the plan in this issue (5-minute verified-cache TTL with group re-resolution, Nikola's decision), and it also feeds #839 for sessions.

**LDAP part confirmed over the real protocol (2026-10-03).** **Setup:** - Mokapi 0.52.0 serves the mock AD on `ldap://127.0.0.1:3890`. The LDIF is hot-reloaded on change, so "AD admin actions" are file edits. - A local Cairn build of main runs in `auth.mode: ldap` with `adminGroups: ["cairn-admins"]`. - User `anna` has `memberOf: cn=cairn-admins` and a `groupOfNames` entry. - After each change, I checked the directory side with `ldapsearch` to prove the mock had changed. | Step | Directory (ldapsearch) | Cairn | |---|---|---| | T0: sign in | accepts | `/api/v1/me` admin=true, groups=[cairn-admins]; WebDAV 207 | | T1: password changed in AD | old **rejected**, new accepted | old password still **accepted** (API and WebDAV 207) until the new one was used once, which overwrote the cache entry | | T2: removed from cairn-admins in AD | memberOf count 0 | **admin=true, groups=[cairn-admins]** (stale) | | T3: account deleted in AD | bind rejected, 0 entries | **still signs in, admin=true, WebDAV 207** | | T4: wrong password never cached | rejected | refused (correct) | **Conclusion.** A person disabled or removed from the admin group in AD keeps full admin access to Cairn over WebDAV and the API until Cairn restarts. This is the exact scenario from Manuel's banking, cantonal and military requirement. It confirms the plan in this issue (5-minute verified-cache TTL with group re-resolution, Nikola's decision), and it also feeds #839 for sessions.
Author
Owner

Decisions (Nikola, 2026-10-03), continued:

  • Where the 5-minute setting lives: the LDAP/AD verified-cache TTL is config only. It's a key in config.json with an env override; the default is 5 minutes. Users & access shows it read-only.
  • Approach: a per-request recheck tied to a per-account counter that goes up on every password, role or existence change, plus active sign-out on changes, with a directory re-check every TTL. This covers #839 too.
  • Docs are part of done:
    • deployment.md (config key and env);
    • the LDAP section;
    • Users & access in admin-policy.md;
    • local-accounts.md and account.md (sign-out behaviour).

Open for Nikola: whether OIDC Back-Channel Logout (Keycloak push) joins this batch, and whether CAEP/Shared Signals is filed separately.

**Decisions (Nikola, 2026-10-03), continued:** - **Where the 5-minute setting lives:** the LDAP/AD verified-cache TTL is **config only**. It's a key in config.json with an env override; the default is 5 minutes. Users & access shows it read-only. - **Approach:** a per-request recheck tied to a per-account counter that goes up on every password, role or existence change, plus active sign-out on changes, with a directory re-check every TTL. This covers #839 too. - **Docs are part of done:** - deployment.md (config key and env); - the LDAP section; - Users & access in admin-policy.md; - local-accounts.md and account.md (sign-out behaviour). Open for Nikola: whether OIDC Back-Channel Logout (Keycloak push) joins this batch, and whether CAEP/Shared Signals is filed separately.
Author
Owner

Decision (Nikola, 2026-10-06): two config keys, replacing the single-key wording above.

The keys:

  • auth.directoryRecheck (env CAIRN_DIRECTORY_RECHECK, default 5m) sets how often sessions re-check the directory.
  • auth.ldapCacheTTL (env CAIRN_LDAP_CACHE_TTL) sets how long WebDAV and other per-request LDAP credentials are trusted. It follows directoryRecheck unless it is set itself.

Rules:

  • Bounds are 30 s to 1 h. A typo or out-of-range value fails startup.
  • Cairn logs a startup WARN when ldapCacheTTL is longer than directoryRecheck.
  • Users & access shows both values read-only.
  • Docs (deployment.md resolution table, the LDAP section, Users & access) are a merge gate for the implementation PR.

Spec: docs/superpowers/specs/2026-10-03-revocation-design.md on branch revocation-838-839 (commit e52a0af8).

**Decision (Nikola, 2026-10-06): two config keys**, replacing the single-key wording above. The keys: - `auth.directoryRecheck` (env `CAIRN_DIRECTORY_RECHECK`, default 5m) sets how often sessions re-check the directory. - `auth.ldapCacheTTL` (env `CAIRN_LDAP_CACHE_TTL`) sets how long WebDAV and other per-request LDAP credentials are trusted. It **follows `directoryRecheck` unless it is set itself.** Rules: - Bounds are 30 s to 1 h. A typo or out-of-range value fails startup. - Cairn logs a startup WARN when `ldapCacheTTL` is longer than `directoryRecheck`. - Users & access shows both values read-only. - Docs (deployment.md resolution table, the LDAP section, Users & access) are a merge gate for the implementation PR. Spec: `docs/superpowers/specs/2026-10-03-revocation-design.md` on branch `revocation-838-839` (commit e52a0af8).
Author
Owner

Correction: the spec commit referenced above (e52a0af8) was made from a working copy that macOS's /tmp cleanup had partly emptied. Its commit -a also recorded 652 file deletions on the branch. I caught it before any PR, rewrote the branch, and force-pushed only the feature branch with a lease; main was never touched. The spec now lives at 089edec5 on revocation-838-839, which has the full tree of 719 files. Working copies moved out of /tmp.

Correction: the spec commit referenced above (e52a0af8) was made from a working copy that macOS's /tmp cleanup had partly emptied. Its `commit -a` also recorded 652 file deletions on the branch. I caught it before any PR, rewrote the branch, and force-pushed only the feature branch with a lease; main was never touched. The spec now lives at **089edec5** on `revocation-838-839`, which has the full tree of 719 files. Working copies moved out of /tmp.
Cordy closed this issue 2026-10-06 17:00:01 +00:00
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#838
No description provided.