Repository navigation
fix(audiobooks): refuse Audiobookshelf tokens minted during a sign-out everywhere - #2919
Conversation
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
|
Warning Review limit reachedEnable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing. Next included review available in 6 minutes. View limit details
|
Quick104
left a comment
There was a problem hiding this comment.
Reviewed 88ef6476b464c416c355e065ec80b0f1649c1583. No actionable defects found.
The two new database tests pass against an isolated Postgres instance with the head migrations: sign-in, refresh, and /authorize refuse issuance after account-wide revocation, and both account-lock orderings preserve revocation. The handler test fails against the merge-base implementation: all three requests return 200 and leave new live tokens. Removing FOR SHARE in a scratch overlay also makes both lock-order tests fail. Focused refresh, authorize, and PIN tests pass.
The transaction holds the account lock through source validation and token writes. Refresh revocation and both replacement tokens commit together, so a failed write preserves the old token for retry. No live client was exercised; the evidence verifies handler and database behavior, not recovery UX.
Validated features: none of the 117 inspected passed result cells require revalidation. The native session/admin and Jellyfin paths remain unchanged; ABS cases #1247 C1–C3 are still Not run on the deferred beta surface. Validation tasks: none is appropriate. Full project enumeration was unavailable because the token lacks read:project; live issue bodies and comment-only results supplied the evidence. No validation records were changed.
The credentials-plugin sign-in race (#2920) and ordinary ABS profile-logout race (#2921) remain pre-existing, separately tracked limits. They are accurately disclosed. Native API and first-party client contracts are unchanged. The manual already says password resets sign devices out, so no manual correction was identified.
Fit: 10/10 · Readiness: 9/10 — ready (assuming CI is green).
Reviewed with Codex and gpt-6.1-sol at xhigh, using independent finder, validation, and sweep passes. No product code was changed.
…t everywhere Audiobookshelf-compatible sign-in, refresh, and /authorize stored new tokens in separate statements outside the account lock that every sign-out everywhere takes, so a sign-out committing between the credential check and the insert left the new tokens working. Tokens are now stored by TokenStore.IssueTokens in one transaction that holds the account's users row FOR SHARE, refuses a missing or disabled account, and rechecks what the tokens come from: the login session the sign-in's credential check opened, the refresh token being rotated (revoked in the same transaction), or the token /authorize was called with. The request gets 401 when that credential was revoked. Closes #2907 Co-Authored-By: Claude Opus 5.5 <[email protected]>
88ef647 to
7765800
Compare
Silo Kody — review completeReview finished. Check the inline comments for findings and verify each suggestion against the code and tests. Reviewing changes in Silo
Review settingsReview OptionsThe following review options are enabled or disabled:
|
…3302) #2919 made the token store refuse tokens issued with no source credential, and #2793 added a login test whose principal carries none. Each passed CI alone; together they fail `go test` on main. Co-authored-by: Claude Opus 5.5 <[email protected]>
Problem
Closes #2907
Related issue: N/A
Validation tasks: none
An Audiobookshelf-compatible app could stay signed in after its account was signed out everywhere (a password reset, an admin setting the password, an admin's Sign out everywhere, disabling the account). If the sign-out committed while the app was signing in, refreshing its token, or calling
/authorize, the tokens that request stored afterwards kept working, for up to 30 days in the case of a refresh token. This change makes those requests store their tokens only while the credential they started from is still valid, and refuses them with 401 otherwise.Every sign-out everywhere locks the account's
usersrow and then revokes itsabs_sessionsrows in one statement. The Audiobookshelf handlers stored new rows in separate statements without that lock: refresh revoked the old token, then inserted the new pair; sign-in checked the password (opening a login session), then inserted;/authorizechecked the presented token, then inserted. A revocation that committed in between could not see rows inserted after it.Approach
TokenStore.InsertTokenandRevokeTokenIfActiveare replaced byIssueTokens, which stores tokens in one transaction that:usersrowFOR SHARE, so it waits for a sign-out in progress, and a sign-out that starts later waits for it and then revokes what it stored;abs.Principal.LoginSessionID), the refresh token being rotated (revoked in the same transaction, which keeps one-winner rotation), or the token/authorizewas called with.When that check fails the store returns
ErrNotFoundand the handler answers 401, which these apps already treat as "sign in again".handleRefreshnow reads the old token's row before minting and leaves the revocation toIssueTokens, so a failed rotation rolls back and the old refresh token still works for a retry. A refresh token that fails the user, profile, type, or expiry checks is no longer revoked as a side effect; it fails those checks on every use anyway.The issuance rule is added to
docs/architecture/password-resets.md. Jellyfin-compatible sessions need no change: they already end with the login session they came from. No API, client, or schema change.Validation
mainfor all three paths (sign-in, refresh,/authorizeeach returned 200 and left live tokens after the sign-out) and passes with the fix. A second test holds each side of the account lock in turn and fails in both orders ifFOR SHAREis removed. Both are listed inscripts/ci/db-contracts.txtand pass under thedbpinsrunner.go build ./...,gofmt -l .,go vet ./...,make lint-changed,make lint-router-recovery,make verify-local-paths: clean.go test -raceon the touched packages: pass.make test-go: one failure,internal/mediasampleTestRunStatsWithRealFFmpeg, which fails the same way onmainwith the local ffmpeg build.Evidence
No user-visible change. The page holds the test runs on
mainand on this branch.Evidence: https://evidence.siloserver.org/r/silo-server/issue-2907/
Risks
/authorizenow briefly holds the account'susersrowFOR SHARE. These requests are infrequent, and the transaction does no hashing or network work. A weaker lock mode would not serialize withEnableAccountLocalLogin, which revokes after a plainUPDATE users.Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Reject Audiobookshelf tokens minted during sign-out everywhere
InsertTokenandRevokeTokenIfActiveon the token store with a singleIssueTokensoperation in abs_session_store.go. It locks the account row FOR SHARE, rejects missing or disabled accounts, validates the source credential (login session or JTI), and inserts all tokens in one transaction./authorizein login.go now issue tokens throughIssueTokens. If the source credential was revoked (sign-out everywhere), the handler returns HTTP 401 without storing tokens.TokenSourcenow requires a login-session ID at sign-in; the in-memory test store checks the source descriptor but not a session store, so out-of-treeTokenStoreimplementations must move toIssueTokens.Macroscope summarized 7765800.