Repository navigation
fix(auth): bind tokens to their session's account and lock directory sign-ins - #3140
Conversation
…sign-ins The per-request session check confirmed that a token's session was active and that the session's account held the token's role, but not that the token's user ID was that account. ActiveSession now takes the user ID the credential names and matches it in the same primary-key query; every caller passes the ID from the token or grant it already verified. A credentials-plugin (LDAP) sign-in inserted its login session after account resolution committed, without locking the account again, so an account disabled in that window kept a working session until its access token expired. It now opens the session through OpenIdentitySession, under the account, installation and identity locks an OAuth sign-in takes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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 36 minutes. View limit details
Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
The change is visible in two authentication outcomes, but the linked evidence is described as test output rather than before-and-after API responses. Please add excerpts for:
Automated check: Macroscope check run agent (gpt-6-luna). Evidence was not reviewed for correctness. Posted via Macroscope — Visible change evidence |
| pair, err := s.OpenIdentitySession(ctx, nil, IdentitySession{ | ||
| UserID: user.ID, | ||
| IdentityID: identityID, | ||
| DeviceName: deviceName, | ||
| IP: ip, | ||
| RefusePasswordChange: refusePasswordChange, | ||
| }) |
There was a problem hiding this comment.
Authentication failure in internal/auth/service.go occurs because non-local providers registered through RegisterProvider always enter OpenIdentitySession, but only the *PluginProvider authentication branch populates identityID; an AuthProvider that successfully returns a user therefore reaches lockOAuthIdentity with identityID == 0 and receives ErrNotPermitted instead of a session. Restrict identity-backed session opening to providers that supplied a plugin identity, and preserve an account-locked session path for other registered providers.
Prompt for LLM
File internal/auth/service.go:
Line 828 to 834:
Authentication failure in internal/auth/service.go occurs because non-local providers registered through RegisterProvider always enter OpenIdentitySession, but only the *PluginProvider authentication branch populates identityID; an AuthProvider that successfully returns a user therefore reaches lockOAuthIdentity with identityID == 0 and receives ErrNotPermitted instead of a session. Restrict identity-backed session opening to providers that supplied a plugin identity, and preserve an account-locked session path for other registered providers.
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
There was a problem hiding this comment.
No current deployment hits this. In production the only password providers are the local provider, handled by the branch above, and the *PluginProvider instances that authProviderRegistry builds, so identityID is always set when this line runs. deps.AuthProviders is set only by the scenario executor (internal/scenariocatalog/executor/env.go), and its rejectingProvider refuses every login before a session is opened. A non-plugin provider added later would get ErrNotPermitted here. That fails closed: it refuses the sign-in instead of opening a session outside the account lock, which is the race this PR closes. If such a provider is ever added, it should get its own identity row rather than reuse the unlocked sessions.Create path.
There was a problem hiding this comment.
Agreed. Given the provider wiring you described, this is not a current authentication regression, and the critical severity is unwarranted. The finding identified a hypothetical successful non-plugin provider, not a reachable production sign-in path.
My recommendation to preserve a separate session-opening path was unnecessary for this PR. Keeping identity-backed session creation ensures the account-locking protection remains intact; an unsupported provider failing closed is not a reason to bypass it.
A future successful non-plugin provider should explicitly integrate with the identity-backed flow. That is future integration work, not a blocker for this security fix.
|
Both changes are covered in the Evidence section. A token whose user ID differs from its session's account now gets the revoked-session 401. A directory sign-in racing a disable now gets the disabled-account refusal. The evidence page has the output of the regression tests that drive both cases, failing on the unfixed code and passing on this branch. A live before-and-after response would need a forged token or a timed race, and the tests already show the same thing. |
Resolve the conflict in internal/api/router.go by keeping this branch's removal of resolveOptionalPluginAccess(User); caller resolution lives in internal/api/plugin_access.go. Port Silo-Server#3140's ActiveSession signature (session id plus user id) to the plugin session checker and its test fake. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Problem
Related issue: #2920
Validation tasks: none
A login session could authenticate a token that names a different account, and a directory (LDAP) sign-in could leave a working session on an account an administrator had just disabled. An automated security scan found both, and a separate agent re-verified each against the code.
This change makes a session answer only for its own account, and opens directory sign-in sessions under the account lock.
Approach
SessionRepository.ActiveSessionnow takes the user ID the credential names and matches it in the same primary-key query, so the per-request check costs no extra statement. Because it is a parameter, every caller has to supply it: the auth middleware, direct-download links, Apple push display tokens, credential revalidation, the v1 events socket, the v2 socket validator, theme-song grants, the node media grant and plugin launch tokens each pass the user ID from the token or grant they already verified. Every token Silo issues names its session's own account, including impersonation tokens (which name the viewed account, the one that owns the session), device sign-in, remote-playback handoffs and refreshed tokens, so legitimate clients see no difference. A mismatched token gets the same 401 as a revoked session.A directory sign-in now opens its session through
OpenIdentitySession, the path OAuth completion and network sign-in already use. It locks the account, refuses a disabled one, locks the enabled installation and the linked identity, and inserts the session in that transaction. Disabling an account takes the same row lock and revokes the account's sessions in its own transaction, so either the disable revokes the new session or the sign-in sees the disabled account. Jellyfin and Audiobookshelf sign-ins through the directory still refuse an account that holds a temporary password, now checked under the lock as the local path does.The request-time check still does not require
users.enabled. The recorded contract scenariome.disabled_accountpins a 200 for a disabled account's still-valid session on v1 and v2, and with this change no live session should outlive a disable, so tightening it is left as a separate contract decision.#2920 stays open: a directory sign-in that overlaps a plain Sign out everywhere (no disable, unlink or password change) can still finish after the sign-out and keep its session. That matches what local password sign-ins do today.
Validation
internal/authwith DB tests,internal/api/middleware,internal/api/handlers,internal/api,internal/apiv2,internal/proxy): pass. One handlers test with a fixed one-second wait timed out once while the machine was loaded and passes alone; it does not reach the session check.main.make test-go: passes except five packages with known local failures on macOS (case-insensitive file system, non-UTF-8 file names, a Dolby Vision PlaybackInfo case, a real-FFmpeg timeout). None touches the changed code.go build,gofmt,go vet,make lint-changed,make lint-router-recovery: pass.Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-3140/
No screen changes. Two responses change. An access token whose user ID is not its session's account, which Silo never issues, now gets the 401 a revoked session gets. A directory sign-in that races an administrator disabling the account now gets the disabled-account refusal instead of a session. Neither shows on a client screen. The evidence page has the test output.
Risks
Core authentication: every authenticated request goes through the changed query. The added predicate is on the row already fetched by primary key. A third-party tool that minted its own tokens with the server's secret and mismatched user and session IDs would stop working; Silo does not support that.
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Bind login sessions and tokens to their account and lock directory sign-ins
SessionRepository.ActiveSessionin session.go now takes a user ID and reports a session as active only for its owning account; all middleware, handler, and proxy session checks pass the token or grant's user IDOpenIdentitySession, which rechecks the account and linked identity under locks before creating the session, so a disable or unlink between steps refuses sign-inIdentitySessionto refuse sign-in when the account requires a password changeErrUserDisabledand no live sessionRequireAuth,RevalidateCurrent, socket validators, theme-song grants, direct-download links, plugin access, Apple push display, media grants); checkActiveSessioncallers and theiruserIDargumentsMacroscope summarized fc268dc.