Skip to content

feat(auth): let a password change sign out other devices - #2925

Merged
Quick104 merged 3 commits into
mainfrom
feat/account-sign-out-other-sessions
Oct 31, 2026
Merged

Quick104 merged 3 commits into
mainfrom
feat/account-sign-out-other-sessions

Conversation

@Quick104

@Quick104 Quick104 commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #2898
Related issue: N/A
Validation tasks: changes #1229 C1 (the new checkbox takes the server accent color)

Changing your own password in Settings > Account leaves every other sign-in working: other browsers and apps, Jellyfin-compatible clients, Audiobookshelf-compatible clients, and device sign-ins you approved that the device hasn't collected yet. Someone who changes the password because they think it leaked can't lock out whoever used it, short of signing each session out by hand (and Audiobookshelf sessions and device approvals aren't listed anywhere). An administrator setting the password, or a reset link, already signs the account out everywhere.

This keeps the default (a password change signs nothing else out) and adds an opt-in: a Sign out of other devices checkbox on the password form, unticked by default, backed by a new optional sign_out_other_sessions member on POST /api/v2/account/password.

Approach

When sign_out_other_sessions is true, the password change revokes what a password reset revokes, except the session making the change, in the same transaction as the password swap: the account's other login sessions (including "View as user" sessions in either direction), its Audiobookshelf-compatible sessions, its stored Jellyfin-compatible sessions, and its approved, uncollected device sign-ins. API keys survive, as after a reset. After commit, the existing OnUserSessionsRevoked hook runs, so every node drops the Jellyfin-compatible sessions it holds in memory. The new RevokeOtherSignInsInTransaction shares its SQL with RevokeSignInsForUsersInTransaction; existing callers keep no session and revoke the same rows as before.

Contract: the member is optional and defaults to false; null is a 422. The response stays 204. GET /api/v2/account/password/capability gains sign_out_other_sessions. Servers without this change reject the member as unknown, so clients send it only when the capability says so; the web form follows that rule. /api/v1 is unchanged. Docs: docs/auth-api.md, docs/architecture/password-resets.md, and the migration ledger notes.

Validation

  • Live on a disposable Silo dev deployment, with one account signed in from two browsers, a Jellyfin-compatible client and an Audiobookshelf-compatible client: after a change with the box unticked, all four still worked; after a change with it ticked, the browser that made the change stayed signed in, the other browser was sent to sign-in, and the Jellyfin and Audiobookshelf clients got 401. Database counts matched each step (live login sessions 4 → 4 → 1, Jellyfin sessions 1 → 1 → 0, Audiobookshelf tokens 2 → 2 → 0). An admin password reset still signed every session out.
  • New Postgres test: without the option nothing else is signed out; with it the caller survives, the account's other sign-ins of every kind end, another account keeps its own, and the hook runs once. It can't build against main (new option); removing the clause that keeps the caller's session, or ignoring the flag, makes it fail.
  • The web test for the checkbox fails against main (no checkbox) and passes here. The v2 handler test covers the member, its default, and null.
  • Gate: Go build, gofmt, go vet, make lint-changed, router-recovery lint, web lint/format/build/budget, make test-web, and every contract and hygiene verifier pass. make test-go passes except internal/mediasample TestRunStatsWithRealFFmpeg, which fails the same way on main with the local ffmpeg build. make verify-actionlint was not run (no workflow changes; actionlint not installed locally). After rebasing onto current main, the focused internal/auth, internal/apiv2 and internal/api/handlers tests, the AccountSettings web test, changed-line lint and the v2 contract verifiers pass. The new Postgres test runs in CI's database-contracts job. internal/audiobooks/abs TestTokenHandlers_ScopeLibrariesToAuthenticatedProfile fails the same way on main, as does make verify-route-inventory; this pull request touches neither the package nor any route.

Evidence

Evidence: https://evidence.siloserver.org/r/silo-server/issue-2898/

Surface and build: web app Settings > Account, desktop and phone width, sandbox built from origin/main (before) and this branch (after).

Risks

Follow-ups

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (via T3 Code)
  • Tool(s): Claude Code, GitHub CLI, T3 Code delegated tasks, Playwright (evidence capture)
  • Model(s): claude-opus-5-5 (implementation and review), gpt-6.1-sol (plan review), claude-sonnet-5-5 (review subagents)
  • Involvement: Fully AI-generated (maintainer review pending)
  • Adversarial review: gpt-6.1-sol reviewed the plan before implementation. It found that a null member would slip past validation (fixed with the existing null guard), that the user manual needs an update (tracked below), and a pre-existing Audiobookshelf race (filed as [bug] An Audiobookshelf token refreshed during a sign-out-everywhere stays valid #2907). A multi-agent code review of the final diff (claude-opus-5-5 finders and verifiers, claude-sonnet-5-5 for the cleanup and validation passes) confirmed that the web form sent the member without checking the capability, which would fail every password change against an older node; the form now shows the checkbox only when offered and sends the member only when ticked. It also flagged a copy assertion in the web test, now removed. It refuted the other candidates with evidence: the hook's request context (Jellyfin lookups re-read the stored row), widening the temporary-password revoke (those sign-ins can't exist under a temporary password), and the default-path test step (the only guard that the default stays). The background adversarial review (gpt-6.1-sol, reviewed a655084) found nothing further.

🤖 Generated with Claude Code

Note

Add sign_out_other_sessions option to v2 password change

  • Adds an optional sign_out_other_sessions boolean to the v2 change-password request, with a matching capability flag in the account-password capability response (required in the schema). The v1 handler and API do not expose it.
  • When set, the password change revokes the account's other sign-ins (login sessions, Jellyfin- and Audiobookshelf-compatible sessions, approved device logins) in the same transaction, keeping the caller's session, then runs the configured revocation hook with a 30-second timeout detached from request cancellation. Core logic lives in Service.ChangePassword and UserRepository.ReplacePasswordSigningOutOthers in service.go and repository.go.
  • The web account settings form shows a capability-gated checkbox, unchecked by default, and invalidates the cached login-sessions query after an opted-in change. Includes OpenAPI/TypeScript schema updates, docs, and a database-backed integration test TestChangePasswordSignOutOtherSessionsDB.
  • Behavioral Change: ChangePassword gains a boolean argument on accountPasswordService, AccountPasswordService, and AccountService interfaces; v2 rejects a null sign_out_other_sessions member, and omission defaults to no sign-out (existing behavior).

Macroscope summarized aa593a6.

@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Oct 22, 2026
@silo-kody

silo-kody Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@coderabbitai

coderabbitai Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bdd6b8e1-f8d9-4127-9c30-9bba88d92b25
Commits

Reviewing files that changed from the base of the PR and between 312d70c and aa593a6.

Files selected for processing: 23
  • contracts/api/v2/fixtures/get_account_password_capability_ok.json
  • contracts/api/v2/fixtures/get_account_password_capability_secondary_profile.json
  • contracts/api/v2/migration.json
  • contracts/api/v2/openapi.json
  • docs/architecture/password-resets.md
  • docs/auth-api.md
  • internal/api/handlers/auth.go
  • internal/api/handlers/auth_password.go
  • internal/api/handlers/auth_password_test.go
  • internal/api/router.go
  • internal/apiv2/account.go
  • internal/apiv2/account_test.go
  • internal/apiv2/pilot_fakes_test.go
  • internal/apiv2/router.go
  • internal/auth/login_sessions_db_test.go
  • internal/auth/password_reset.go
  • internal/auth/repository.go
  • internal/auth/service.go
  • scripts/ci/db-contracts.txt
  • web/src/api/v2/schema.ts
  • web/src/hooks/queries/account.ts
  • web/src/pages/settings/AccountSettings.test.tsx
  • web/src/pages/settings/AccountSettings.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

Walkthrough

The v2 password-change flow adds an optional setting to revoke other account sessions during password replacement. The calling session and API keys are retained. The account settings form exposes the option when supported.

Changes: Password-change sign-out

Layer / File(s) Summary
API contract and request wiring
contracts/api/v2/*, docs/auth-api.md, internal/api/handlers/auth*.go, internal/apiv2/*
The v2 capability and password-change request expose sign_out_other_sessions. The endpoint rejects null and forwards the value to the account service. The v1 handler passes false.
Transactional session revocation
internal/auth/*, internal/api/router.go, internal/auth/login_sessions_db_test.go, scripts/ci/db-contracts.txt, docs/architecture/password-resets.md
When sign-out is requested, password replacement and revocation of other active sign-ins occur in one transaction. The requesting session is preserved. After success, the service invokes the configured revocation callback. Database tests cover sign-in types, account boundaries, and the callback.
Web password setting
web/src/api/v2/schema.ts, web/src/hooks/queries/account.ts, web/src/pages/settings/AccountSettings*
The form shows an unchecked checkbox when the capability supports the option. It submits the flag when selected, displays a corresponding success message, and invalidates login-session queries after a successful sign-out change.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant AccountSettings
  participant PasswordEndpoint as v2 password endpoint
  participant AccountService
  participant authService as auth.Service
  participant Repository
  participant RevocationHook as OnUserSessionsRevoked
  AccountSettings->>PasswordEndpoint: Submit password and sign_out_other_sessions
  PasswordEndpoint->>AccountService: Pass sign-out setting
  AccountService->>authService: ChangePassword with sign-out setting
  authService->>Repository: Replace password and revoke other sign-ins
  Repository-->>authService: Return after transaction
  authService->>RevocationHook: Notify after successful change
  PasswordEndpoint-->>AccountSettings: Return successful response
Loading

Possibly related PRs

Suggested reviewers: rhainland

Merge Risk: Minimal · up to aa593

The optional sign-out path preserves the temporary-password transition, and no unresolved issue in the supplied evidence prevents merging after normal checks.

Security architecture risk: Low · up to aa593

The change retains existing password and account-authority checks and makes password replacement and sign-out transactional. No new security weakness was established in the inspected flow, but deployment-specific invalidation and recovery behavior remain partially verified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The new request controls whether to revoke sign-ins, not which account or session to target. Those identifiers are supplied from authenticated claims. The revocation predicate also reaches impersonation sessions associated with that account, including sessions whose viewed account differs.

Security Findings and Attack Paths

  • inferred — A process interruption or failed event publication after commit can skip cache eviction, but that alone does not demonstrate continued use of a revoked persistent Jellyfin-compatible credential: subsequent persistent lookup reads the deleted row, and refresh updates cannot recreate it. This is counterevidence to a notification-loss vulnerability, not assurance about every deployment configuration.

Trust Boundaries and Controls

  • observed — The changed endpoint retains the shared authorization check. It rejects missing access-session claims and impersonation, and applies the existing primary-profile or administrator rule, with the existing temporary-password exception. Credential replacement additionally validates the current password and uses an expected-hash update to reject stale replacements.

Resilience and Maintainability Implications

  • inferred — The inspected transition paths serialize relevant credential issuance with password replacement through the account row. Local sign-in rechecks the password under that lock; Audiobookshelf issuance takes a conflicting shared lock; device collection locks the approving account before the device request. These controls limit concurrent issuance escaping the revocation boundary.
Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "feat(auth): let a password change sign out other devices" matches the main change: an opt-in optional sign_out_other_sessions flag on POST /api/v2/account/password that revokes other sign-i…
Description check Passed The description states the problem (other sign-ins survive a password change), the approach (opt-in sign_out_other_sessions member, capability endpoint, revocation in the same transaction, hook invoca…
Linked Issues check Passed [#2898] Each coding objective has implementation at the reviewed head.

1. Optional sign_out_other_sessions boolean, default false, on POST /api/v2/account/password: ChangePasswordInput keeps `R…
Out of Scope Changes check Passed Each changed area supports the #2898 feature:

- Contract artifacts (contracts/api/v2/openapi.json, fixtures, migration.json), web/src/api/v2/schema.ts, and docs/auth-api.md and `docs/architec…
Full details: Title check

Explanation

The title "feat(auth): let a password change sign out other devices" matches the main change: an opt-in optional sign_out_other_sessions flag on POST /api/v2/account/password that revokes other sign-ins (login sessions, Jellyfin- and Audiobookshelf-compatible sessions, approved device sign-ins) while keeping the caller's session. The title is specific, concise, and follows a conventional commit form. It does not mention the capability endpoint or the web checkbox, which is expected for a single headline.

Full details: Description check

Explanation

The description states the problem (other sign-ins survive a password change), the approach (opt-in sign_out_other_sessions member, capability endpoint, revocation in the same transaction, hook invocation), validation steps, contract notes, risks, and follow-ups. It is directly related to the changeset and is not off-topic.

Full details: Linked Issues check

Explanation

[#2898] Each coding objective has implementation at the reviewed head.

  1. Optional sign_out_other_sessions boolean, default false, on POST /api/v2/account/password: ChangePasswordInput keeps RawBody and Body.SignOutOtherSessions (internal/apiv2/account.go). A JSON null is rejected with 422. Omission passes false.
  2. Same-transaction revocation, keeping the caller's session: ReplacePasswordSigningOutOthers runs RevokeOtherSignInsInTransaction inside the compareAndSwapPassword transaction, before commit (internal/auth/repository.go). revokeSignInsInTransaction excludes only id IS DISTINCT FROM keepSessionID.
  3. Other login sessions, including "View as user" sessions: the SQL matches user_id or impersonator_user_id (internal/auth/password_reset.go).
  4. Audiobookshelf sessions, Jellyfin-compatible sessions, approved uncollected device sign-ins: revoked by revokeAudiobookshelfSessionsInTransaction, deleteJellyfinSessionsInTransaction, and withdrawDeviceSignInApprovalsInTransaction in the same transaction.
  5. API keys survive: the revocation SQL does not touch API key tables.
  6. Post-commit Jellyfin in-memory invalidation: Service.OnSessionsRevoked is wired to deps.OnUserSessionsRevoked (internal/api/router.go). The hook runs after the password change returns. The ReplacePasswordSigningOutOthers doc comment states this.
  7. Capability reporting: AccountPasswordCapabilityView.SignOutOtherSessions (internal/api/handlers/auth_password.go, internal/apiv2/account.go).
  8. Unticked web checkbox, shown only when the capability reports support: AccountSettings.tsx, per the change summary and the web test.
  9. /api/v1 unchanged: HandleChangePassword passes false.

Tests: a database test TestChangePasswordSignOutOtherSessionsDB, v2 handler tests for default, true, and null, and a web test for the checkbox. The reported test results were not re-run in this assessment.

[#2907] Closed and contextual only. Its Audiobookshelf race is not a requirement for this pull request. The PR states that #2919 addresses it.

Limit: service.go was read only in part. The ChangePassword body was not inspected. Its post-commit hook ordering rests on the change summary and the doc comments.

Full details: Out of Scope Changes check

Explanation

Each changed area supports the #2898 feature:

  • Contract artifacts (contracts/api/v2/openapi.json, fixtures, migration.json), web/src/api/v2/schema.ts, and docs/auth-api.md and docs/architecture/password-resets.md: document and type the new v2 member and capability. The v1 contract is unchanged.
  • internal/api/handlers/auth.go, auth_password.go, auth_password_test.go, internal/apiv2/router.go, pilot_fakes_test.go: thread the new boolean through service interfaces. The v1 path passes false.
  • internal/auth/service.go, password_reset.go, repository.go: implement the revocation and post-commit hook.
  • internal/auth/repository.go refactor: compareAndSwapPassword now takes a transaction callback. The temporary-password path still runs the same UPDATE auth_sessions statement, with the same keepSessionID semantics. The diff shows no behavior change there. RevokeSignInsForUsersInTransaction keeps its previous behavior with a nil keep session.
  • web/src/hooks/queries/account.ts: invalidates login-sessions only after an opted-in change. This keeps the cached session list accurate.
  • scripts/ci/db-contracts.txt: registers the new database test.

No unrelated feature, refactor, or file change was found.

Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 15 files. (8 skipped: 7 unsupported, 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

Finishing Touches
Generate docstrings
  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-triage silo-triage Bot added api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase enhancement New feature or request go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P2 Limited scope, workaround exists, or polish labels Oct 22, 2026

@Quick104 Quick104 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 402363789304a7dbf9d9ee3b03c0f4e70e816777: no introduced defect found.

Focused checks passed: four database tests covering opt-in revocation, caller preservation, existing admin revocation, rollback and device-poll serialization; three v2 account tests; and four web form tests. The checkbox test fails on the merge base because the control is absent. The new Go database test cannot build on that base because it uses the new service signature, so that run is not regression proof.

The disclosed Audiobookshelf refresh race remains real and unresolved in #2907: a concurrent refresh can insert replacement tokens after revocation. It predates this diff and the new option inherits it; this review does not establish complete sign-out under that race.

Suggested validation line for recorded passes: Validation tasks: changes #1229 C1. Session cases #1186 C1 and #1187 C1 remain Not run and should exercise the new option; #1229 C1 needs a minor appearance re-check. Existing API-key and impersonation cases retain their behavior. Validation used live issue records; full board enumeration was unavailable because the GitHub token lacks read:project.

The manual follow-up is tracked by Silo-Server/siloserver.org#280 and its draft PR #281. Apple and Android currently have no password-change screen.

Fit: 9/10 · Readiness: 8/10 — conditional on accepting the documented #2907 limitation. CI is green on the reviewed head. No live browser or multi-node exercise was performed in this review.

AI review: Codex desktop, gpt-6.1-sol, xhigh; independent finder and verification passes.

Quick104 and others added 2 commits October 31, 2026 00:13
Changing your own password kept every other sign-in working. v2
changePassword now takes an optional sign_out_other_sessions boolean (off
by default). When set, the password change revokes everything a reset
revokes except the calling session, in the same transaction, and runs the
OnUserSessionsRevoked hook after commit. The password capability reports
the option. The web form shows an unticked "Sign out of other devices"
checkbox when the capability offers it and sends the member only when
ticked. /api/v1 is unchanged.

Closes #2898

Co-Authored-By: Claude Opus 5.5 <[email protected]>
ActiveSession now takes the session's account and CheckPassword takes a
context and reports a busy hasher, so the sign-out-other-sessions DB test
passes each fixture session's owner and checks both results.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Quick104
Quick104 force-pushed the feat/account-sign-out-other-sessions branch from 4023637 to 9724b17 Compare October 31, 2026 04:22
@silo-kody

silo-kody Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

Comment thread internal/auth/service.go Resolved
@macroscopeapp

macroscopeapp Bot commented Oct 31, 2026

Copy link
Copy Markdown

#1229 C1 needs a minor appearance re-check: the new checkbox on Settings > Account adds a control using the branded primary color. The PR body still says Validation tasks: none; please change it to Validation tasks: changes #1229 C1.

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@silo-kody

silo-kody Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@Quick104
Quick104 merged commit 7ee9615 into main Oct 31, 2026
28 of 30 checks passed
@Quick104
Quick104 deleted the feat/account-sign-out-other-sessions branch October 31, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api-v2 API v2 / Huma migration program (epic #135); long-running, stacked by phase enhancement New feature or request go Pull requests that update go code impact: security Auth, privacy, or permission boundary priority: P2 Limited scope, workaround exists, or polish size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] An Audiobookshelf token refreshed during a sign-out-everywhere stays valid [feature] Sign out of other devices when changing your own password

1 participant