Demo: a static copy of one review, without the review service. Reviewed marks apply in this tab until it reloads, and view settings stay in this browser. Comments, decisions, and publication need an installed mcp-review. About mcp-review · Get early access

Snapshot #2 of 2

Snapshot #1 → #2: the earlier snapshot's code against the displayed snapshot.

Harden sign-in: hashed passwords, expiring sessions and per-session rate limits

Sign-in no longer accepts any password, and a session no longer lives forever.

What changes

  • Passwords are hashed with scrypt and a per-user salt. The md5 helpers and the legacy token module are deleted.
  • A session expires 12 hours after it starts, and its token rotates on use.
  • Each session gets a token bucket for requests, stored in Postgres, so a restart does not reset it.
  • The HTTP layer becomes an explicit middleware chain with CORS, request IDs and an event stream.
flowchart LR
  Login[login] --> Session[session]
  Session --> Router[api/router]
  Config[config.port] --> Server[listen 8080]

How to review

Start with Core auth changes and Session store. The scheduled jobs only change their logger import, so that section shows two examples and keeps the other jobs in one group.

Coverage

Presentation
All 143 selected changes are placed. 132 in groups · 0 unbucketed · 4 generated · 7 without a text diff
Explanations
13 of 13 groups have an explanation.
Agent analysis
Reading the analysis status…
Human review
7 of 136 hunks are marked reviewed.

Outdated discussions 1

These discussions have no verified location in the displayed changes. Each keeps its original code and stays open to replies and resolution.

OPEN src/auth.ts Outdated · Ln 27 This token is the user name and the time of the request, so anyone who knows roughly when a user refreshed can guess it. Should it be random, like the session I…
src/auth.ts · new side · Ln 27

The selected new-side lines no longer exist in src/auth.ts.

  session.token = `tok-${session.user}-${Date.now()}`;
You

This token is the user name and the time of the request, so anyone who knows roughly when a user refreshed can guess it. Should it be random, like the session ID in createSession?

Review agent

Yes. The next snapshot sets the token with crypto.randomUUID(), as createSession does for the session ID, so the token no longer depends on the user name or the clock.

Sections

Each section opens on its own page, so the browser loads only the changes of that section. Show all sections on one page

  1. 2 files · 4 hunks · +45 -3 · 0/2 files reviewed · 0 open discussions

    Login validates credentials before it issues a token, and the bearer middleware resolves the session for every other route. A refreshed token is random, so nobody can derive it from the user name and the time of the request.

    Why it matters

    • Empty credentials previously received tokens.
    • A token that the clock decides is guessable.
    • src/auth.ts and the auth middleware also appear in other sections. This section shows only the hunks of this change.
    sequenceDiagram
      participant C as Client
      participant A as auth.login
      C->>A: user, password
      alt missing
        A-->>C: throw
      else ok
        A-->>C: token
      end
    
  2. 3 files · 4 hunks · +34 -219 · 0/3 files reviewed · 0 open discussions

    scrypt with a per-user salt replaces the placeholder hash, and token minting moves into lib/crypto.ts.

    src/auth.ts shows up here as well as under Core auth changes — this section owns only its hashPassword hunk, so each section shows the diff it is actually about.

  3. 6 files · 10 hunks · +85 -192 · 1/6 files reviewed · 0 open discussions

    Session creation requires a user, expiry uses createdAt, rotation happens on use, and the browser hook keeps the token fresh.

    The session SQL lives in src/db/queries.ts, whose remaining hunks belong to Database & migrations.

  4. 16 files · 26 hunks · +817 -330 · 0/16 files reviewed · 0 open discussions

    Router attaches sessions on login, handlers tighten JSON parsing and add an error boundary, and the server grows a middleware chain plus an SSE stream.

    flowchart TB
      R[router] --> H[handlers]
      R --> S[session]
      R --> E[sse]
    
  5. 5 files · 7 hunks · +74 -207 · 0/5 files reviewed · 0 open discussions

    A token bucket per session (falling back to the remote address), persisted so a restart does not hand out a fresh budget.

    The raised retries note in src/config.ts belongs to this change, while the port and loadConfig hunks in the same file sit under Config / glue.

  6. 8 files · 12 hunks · +195 -78 · 0/8 files reviewed · 0 open discussions

    Pool sizing and transactions, the sessions/audit tables, and the queries behind auditing and expiry.

  7. 2 files · 3 hunks · +31 -6 · 2/2 files reviewed · 0 open discussions

    Default port moves 3000 → 8080, loadConfig reads env overrides, and lib/env.ts parses them with explicit defaults.

  8. 11 files · 12 hunks · +348 -129 · 0/11 files reviewed · 0 open discussions

    Login form with local validation, a session badge, a toast, and the styles for all three.

  9. 8 files · 12 hunks · +111 -130 · 0/8 files reviewed · 0 open discussions

    Formatting helpers normalize users, logging becomes structured, and retries get jittered backoff.

  10. 9 files · 13 hunks · +158 -183 · 0/9 files reviewed · 0 open discussions

    Sign-in flow, endpoint table, error codes, rate-limit budgets, changelog.

  11. 6 files · 7 hunks · +139 -13 · 0/6 files reviewed · 0 open discussions

    Node 24, pnpm, a lint/typecheck/test pipeline, an e2e job, and a slimmer image.

  12. 6 files · 6 hunks · +18 -18 · 0/6 files reviewed · 0 open discussions

    Mechanical change · 2 example files · 4 remaining matching files

    Every scheduled job moves from the old logger module to the structured log module. The two examples show the whole change; the other jobs repeat it exactly.

  13. 13 files · 16 hunks · +292 -169 · 0/13 files reviewed · 0 open discussions

    The tests of the production sections above, in the same order: login and hashing, sessions, the HTTP API, rate limiting and the database queries, then the end-to-end passes over the form and the retired fakes.

  14. 7 files · 0 hunks · +0 -0 · 0/0 files reviewed · 0 open discussions

    Selected files that have no text hunks, such as binary, renamed, or unavailable sources. Each file stays in the review with its reason.

  15. 4 files · 4 hunks · +1269 -98 · 0/4 files reviewed · 0 open discussions

    Lockfiles, codegen, and vendored files. Diffs load on demand, no syntax highlighting until asked.

+3,567 -1,767 left