Repository navigation
fix(auth): make unknown sign-in names cost a password check - #2105
Conversation
Password sign-in answered an unknown name, or an account without local password sign-in, before running bcrypt, while a wrong password for an existing account paid for one comparison. The difference (about 1.5 ms against about 57 ms at the default cost) told anyone timing failed sign-ins which names have accounts, on the native and Jellyfin login routes alike. Those rejections now compare the supplied password against a placeholder hash made once, at the cost new passwords get, so every rejection costs one bcrypt comparison. Errors and responses are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <[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:
|
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. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (4)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review. 📝 WalkthroughWalkthroughLocal password authentication now uses a cached placeholder hash for missing accounts and accounts without local password sign-in. A helper handles login lookup and password checks. Tests cover username and email inputs, invalid credentials, and successful authentication. ChangesLocal password authentication
Priority: ⬇️ Low Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix Sequence Diagram(s)sequenceDiagram
participant Authenticate
participant checkLocalPassword
participant LookupLogin
participant comparePasswordHash
Authenticate->>checkLocalPassword: identifier and password
checkLocalPassword->>LookupLogin: resolve identifier
LookupLogin-->>checkLocalPassword: user or not-found error
alt user missing or local password sign-in disabled
checkLocalPassword->>comparePasswordHash: supplied password and placeholder hash
comparePasswordHash-->>checkLocalPassword: comparison result
checkLocalPassword-->>Authenticate: ErrInvalidCredentials
else local password sign-in enabled
checkLocalPassword->>comparePasswordHash: supplied password and stored hash
comparePasswordHash-->>checkLocalPassword: comparison result
checkLocalPassword-->>Authenticate: user or ErrInvalidCredentials
end
Merge Risk: ⚪ Minimal · up to No merge-blocking issue was identified in the local password authentication change; it is ready for normal merge checks. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Problem
Related issue: N/A
Validation tasks: none
Password sign-in rejects an unknown username much faster than a wrong password
for a real account, so anyone can find out which usernames exist by timing
failed sign-ins. The error body is already the same for both. This change
makes every rejected password sign-in run one bcrypt comparison, so the
response time no longer depends on whether the account exists.
LocalProvider.AuthenticatereturnedErrInvalidCredentialsbefore runningbcrypt when the name had no account, or when the account had local password
sign-in turned off (for example an account linked to an external sign-in
provider). A wrong password for an existing account ran one comparison, about
57 ms at the default cost against about 1.5 ms for an unknown name. Every
password surface goes through this check: v1 and v2 login, Jellyfin
AuthenticateByName, and Audiobookshelf compatibility (beta).Approach
Those two early rejections now compare the supplied password against a
placeholder hash and still return
ErrInvalidCredentials. The placeholder isa random password hashed once at the cost new passwords get
(
passwordHashCost), andNewLocalProvidercreates it so the first sign-indoes not pay for it. Error values, response bodies and the order of the later
checks (disabled account, server-wide password switch, network refusal) are
unchanged.
Password hash comparisons now go through a package variable, next to the
existing
passwordHashCosttest hook, so a unit test can see which hash eachrejection compared.
No API contract, client or user manual change: responses stay the same and
only the time an unknown name takes to fail changes.
Validation
name, an unknown email, an account without local password sign-in, a wrong
password and a right password each run exactly one comparison, against the
placeholder or the account's hash. It fails when the placeholder comparison
is removed.
go test ./internal/auth/...against a migrated Postgres databasepasses. The jellycompat, API handler, password reset and audiobooks packages
pass except four tests unrelated to sign-in, which fail the same way on
mainin the same environment.go build ./...,gofmt -l,go vet ./internal/auth/,make lint-changedandmake verify-local-pathspass.unknown name went from 1.5 ms to 57.4 ms median on v2 login and from 1.4 ms
to 57.0 ms on Jellyfin, matching a wrong password for a real account
(57.1 ms and 57.0 ms). Correct passwords still sign in, and the 401 bodies
for unknown names and wrong passwords are unchanged on v1, v2 and Jellyfin.
make test-go(left to CI),go vet ./...over the whole tree,the web checks and the contract
verify-*targets. This change touches noweb code and no API contract.
Timings (ms, N = 20 per case, every response 401)
Cases were interleaved in a shuffled order each round, with a fresh random
password per request and a fresh username for the unknown-name cases. Native
login requests were spaced to stay under the per-IP login limit, and no 429
was recorded.
Evidence
Evidence: https://evidence.siloserver.org/r/silo-server/pr-2105/
Risks
comparison, as a wrong password for an existing account already did. The
per-IP login rate limit still applies.
startup, which takes about as long as one sign-in.
directory's time. Some name forms, such as an email address or a Jellyfin
name#profilesign-in, can still cost an unknown name one or two moredatabase lookups than an existing one; that difference is far smaller than
a bcrypt comparison. A stored hash made at a different bcrypt cost from the
server's would still take a different time.
Checklist
AI Disclosure
🤖 Generated with Claude Code
Note
Run one bcrypt check for unknown sign-in names in
auth.LocalProvider.AuthenticatePrevents timing attacks that reveal whether a login name exists. Unknown names and accounts with local password sign-in disabled now run one bcrypt comparison against a cached placeholder hash before returning
ErrInvalidCredentials.checkLocalPasswordin provider.go, which resolves the login viaLookupLogin, compares rejected cases against the placeholder hash, and verifies real accounts throughCheckPasswordNewLocalProviderconstruction from a random password hashed atpasswordHashCost, and cached inplaceholderPasswordHashin password_hash.goCheckPasswordand tests route through a new package-levelcomparePasswordHashhook so tests can inject and count comparisonsNewLocalProvidercan panic if the initial placeholder bcrypt hash fails; every rejected sign-in now costs one bcrypt comparison (~100ms at default cost)Macroscope summarized 26f3e11.