Skip to content

fix(auth): make unknown sign-in names cost a password check - #2105

Merged
Quick104 merged 1 commit into
mainfrom
fix/login-timing
Oct 8, 2026
Merged

Quick104 merged 1 commit into
mainfrom
fix/login-timing

Conversation

@Quick104

@Quick104 Quick104 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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.Authenticate returned ErrInvalidCredentials before running
bcrypt 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 is
a random password hashed once at the cost new passwords get
(passwordHashCost), and NewLocalProvider creates it so the first sign-in
does 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 passwordHashCost test hook, so a unit test can see which hash each
rejection 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

  • Unit test: a new test without timing assertions checks that an unknown
    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 tests: go test ./internal/auth/... against a migrated Postgres database
    passes. The jellycompat, API handler, password reset and audiobooks packages
    pass except four tests unrelated to sign-in, which fail the same way on
    main in the same environment.
  • Static checks: go build ./..., gofmt -l, go vet ./internal/auth/,
    make lint-changed and make verify-local-paths pass.
  • Timing on an isolated full stack, requests over loopback, 20 per case: an
    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.
  • Not run: make test-go (left to CI), go vet ./... over the whole tree,
    the web checks and the contract verify-* targets. This change touches no
    web code and no API contract.
Timings (ms, N = 20 per case, every response 401)
Case Before median Before p90 After median After p90
v2, unknown username 1.5 1.7 57.4 58.7
v2, existing user, wrong password 57.3 58.0 57.1 58.1
v2, account without local password sign-in 1.7 2.1 57.3 58.5
Jellyfin, unknown username 1.4 1.6 57.0 57.5
Jellyfin, existing user, wrong password 57.0 58.1 57.0 57.6

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

  • A failed sign-in for an unknown name now costs the server one bcrypt
    comparison, as a wrong password for an existing account already did. The
    per-IP login rate limit still applies.
  • Each process that builds a local provider hashes the placeholder once at
    startup, which takes about as long as one sign-in.
  • Not covered: a name that a credentials plugin (LDAP) handles takes the
    directory's time. Some name forms, such as an email address or a Jellyfin
    name#profile sign-in, can still cost an unknown name one or two more
    database 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

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • The Evidence section shows every change a user can see, or says there is none.

AI Disclosure

  • Harness: Claude Code (in T3 Code)
  • Tool(s): Claude Code
  • Model(s): claude-opus-5-5[1m]
  • Involvement: Fully AI-generated, human verification pending
  • Adversarial review: n/a

🤖 Generated with Claude Code

Note

Run one bcrypt check for unknown sign-in names in auth.LocalProvider.Authenticate

Prevents 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.

  • Adds checkLocalPassword in provider.go, which resolves the login via LookupLogin, compares rejected cases against the placeholder hash, and verifies real accounts through CheckPassword
  • The placeholder hash is created once at NewLocalProvider construction from a random password hashed at passwordHashCost, and cached in placeholderPasswordHash in password_hash.go
  • CheckPassword and tests route through a new package-level comparePasswordHash hook so tests can inject and count comparisons
  • Behavioral Change: NewLocalProvider can panic if the initial placeholder bcrypt hash fails; every rejected sign-in now costs one bcrypt comparison (~100ms at default cost)

Macroscope summarized 26f3e11.

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

silo-kody Bot commented Oct 8, 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 ❌

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-08T16:16:31.670743Z 26f3e11 PR opened
🔒 Security Review ✅ Completed 2026-10-08T16:18:49.688140Z 26f3e11 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Quick104 Quick104 added priority: P1 Core-path bug; painful workaround — next after P0 impact: security Auth, privacy, or permission boundary labels Oct 8, 2026 — with Cursor
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 16903bd9-bdf1-4b09-8311-15b19dd97320
📥 Commits

Reviewing files that changed from the base of the PR and between f5f0f54 and 26f3e11.

📒 Files selected for processing (4)
  • internal/auth/password_hash.go
  • internal/auth/provider.go
  • internal/auth/provider_test.go
  • internal/auth/repository.go

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


📝 Walkthrough

Walkthrough

Local 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.

Changes

Local password authentication

Layer / File(s) Summary
Password hash comparison
internal/auth/password_hash.go, internal/auth/repository.go, internal/auth/provider.go
A shared comparison function handles password hash checks. The provider initializes a cached placeholder hash generated from a random password.
Local password check
internal/auth/provider.go, internal/auth/provider_test.go
Authenticate delegates lookup and password verification to checkLocalPassword. Missing accounts and accounts without local password sign-in are checked against the placeholder hash. Tests verify one comparison per case and cover username and email inputs.

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
Loading

Merge Risk: ⚪ Minimal · up to 26f3e

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)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 4 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: adding a password check for unknown sign-in names.
Description check ✅ Passed The description directly explains the timing-attack problem, the placeholder-hash approach, affected authentication paths, tests, validation results, and known risks.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Quick104
Quick104 merged commit 2600125 into main Oct 8, 2026
16 checks passed
@Quick104
Quick104 deleted the fix/login-timing branch October 8, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact: security Auth, privacy, or permission boundary priority: P1 Core-path bug; painful workaround — next after P0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant