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
Change request saved in this viewer
This review has no pull request, so the decision stays in this viewer.
An agent sees the decision only while it watches this review. If the agent is not answering in chat, ask it there: Continue the mcp-review at /demo
This review is archived. It stays readable at this address, and its discussions and pending work continue.
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.
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 0
These discussions have no verified location in the displayed changes. Each keeps its original code and stays open to replies and resolution.
Core auth changes
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
src/auth.ts
+10-1
Difftastic 0.69.0 · TypeScript: changed syntax is marked
Placing the discussions of this file for the layout of this page…
OPENsrc/auth.tsOutdated · Ln 27This 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.
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.
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.
lib/crypto.ts
+29-32
Difftastic 0.69.0 · TypeScript: changed syntax is marked
Placing the discussions of this file for the layout of this page…
// Hashing + token helpers shared by auth and sessions.// Hashing + token helpers shared by auth and sessions.
findSession:'select * from sessions where token = $1',const { rows } =awaitclient.query(`select * from sessions where token = $1 and revoked_at is null`, params);
insertSession:'insert into sessions (id, user_id, token) values ($1, $2, $3)',returnrows;
deleteSession:'delete from sessions where id = $1',}
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]
src/api/debug.ts
+0-21
Difftastic 0.69.0 · TypeScript: changed syntax is marked
Placing the discussions of this file for the layout of this page…
Unchanged since the baseline
// Debug helpers kept for local development.// Debug helpers kept for local development.
exportfunctiondumpSessions(_req, res) {
// unauthenticated: it listed every session in the database
for (constkeyofObject.keys(store)) deletestore[key];
}
exportconstLEGACY_ROUTE_1=1;
exportconstLEGACY_ROUTE_2=2;
exportconstLEGACY_ROUTE_3=3;
exportconstLEGACY_ROUTE_4=4;
exportconstLEGACY_ROUTE_5=5;
exportconstLEGACY_ROUTE_6=6;
exportconstLEGACY_ROUTE_7=7;
exportconstLEGACY_ROUTE_8=8;
exportconstLEGACY_ROUTE_9=9;
exportconstLEGACY_ROUTE_10=10;
exportconstLEGACY_ROUTE_11=11;
exportconstLEGACY_ROUTE_12=12;
exportconstLEGACY_ROUTE_13=13;
exportconstLEGACY_ROUTE_14=14;
exportconstLEGACY_ROUTE_15=15;
exportconstLEGACY_ROUTE_16=16;
exportconstLEGACY_ROUTE_17=17;
exportconstLEGACY_ROUTE_18=18;
exportconstLEGACY_ROUTE_19=19;
exportconstLEGACY_ROUTE_20=20;
exportconstLEGACY_ROUTE_21=21;
exportconstLEGACY_ROUTE_22=22;
exportconstLEGACY_ROUTE_23=23;
exportconstLEGACY_ROUTE_24=24;
exportconstLEGACY_ROUTE_25=25;
exportconstLEGACY_ROUTE_26=26;
exportconstLEGACY_ROUTE_27=27;
exportconstLEGACY_ROUTE_28=28;
exportconstLEGACY_ROUTE_29=29;
exportconstLEGACY_ROUTE_30=30;
exportconstLEGACY_ROUTE_31=31;
exportconstLEGACY_ROUTE_32=32;
exportconstLEGACY_ROUTE_33=33;
exportconstLEGACY_ROUTE_34=34;
exportconstLEGACY_ROUTE_35=35;
exportconstLEGACY_ROUTE_36=36;
exportconstLEGACY_ROUTE_37=37;
exportconstLEGACY_ROUTE_38=38;
exportconstLEGACY_ROUTE_39=39;
exportconstLEGACY_ROUTE_40=40;
exportconstLEGACY_ROUTE_41=41;
exportconstLEGACY_ROUTE_42=42;
exportconstLEGACY_ROUTE_43=43;
exportconstLEGACY_ROUTE_44=44;
exportconstLEGACY_ROUTE_45=45;
exportconstLEGACY_ROUTE_46=46;
exportconstLEGACY_ROUTE_47=47;
exportconstLEGACY_ROUTE_48=48;
exportconstLEGACY_ROUTE_49=49;
exportconstLEGACY_ROUTE_50=50;
exportconstLEGACY_ROUTE_51=51;
exportconstLEGACY_ROUTE_52=52;
exportconstLEGACY_ROUTE_53=53;
exportconstLEGACY_ROUTE_54=54;
exportconstLEGACY_ROUTE_55=55;
src/api/openapi.ts
+173-42
Difftastic 0.69.0 · TypeScript: changed syntax is marked, 1 more on lines that Git shows as unchanged
Placing the discussions of this file for the layout of this page…
// Hand-maintained OpenAPI document; generated/api-types.d.ts is derived from it.// Hand-maintained OpenAPI document; generated/api-types.d.ts is derived from it.
exportconstopenapi= {exportconstopenapi= {
openapi:'3.1.0', openapi:'3.1.0',
Unchanged since the baseline
src/api/router.ts
+7-1
Difftastic 0.69.0 · TypeScript: changed syntax is marked
Placing the discussions of this file for the layout of this page…
const { rows } =awaitclient.query(`select count(distinct user_id)::int as n from sessions where created_at > now() - interval '30 days'`, params);const { rows } =awaitclient.query(`select count(distinct user_id)::int as n from sessions where created_at > now() - interval '30 days'`, params);
returnrows;returnrows;
Unchanged since the baseline
}}
exportfunctionreportLegacy1(input) {
// unused since the reportLegacy rewrite
returnString(input??'').trim();
}
exportfunctionreportLegacy2(input) {
// unused since the reportLegacy rewrite
returnString(input??'').trim();
}
exportfunctionreportLegacy3(input) {
// unused since the reportLegacy rewrite
returnString(input??'').trim();
}
exportfunctionreportLegacy4(input) {
// unused since the reportLegacy rewrite
returnString(input??'').trim();
}
src/db/pool.ts
+31-26
Difftastic 0.69.0 · TypeScript: changed syntax is marked
Placing the discussions of this file for the layout of this page…
session_id uuid referencessessions (id) on deletesetnull,
payload jsonb not nulldefault'{}'::jsonb,
created_attimestamptznot nulldefaultnow()
);
createindexifnotexists audit_events_kind_idx on audit_events (kind, created_at desc);
src/db/migrations/0009_audit_partitions.sql
+50-0
Line diff: Difftastic could not parse this file and compared it as text. Word comparison marks the changed words of replaced lines.
Placing the discussions of this file for the layout of this page…
Unchanged since the baseline
-- 0009: partition audit_events by month so retention is a detach, not a delete-- 0009: partition audit_events by month so retention is a detach, not a delete
altertable audit_events rename to audit_events_legacy;
createtableaudit_events (
idbigserial,
kindtextnot null,
session_id uuid,
payload jsonb not nulldefault'{}'::jsonb,
created_attimestamptznot nulldefaultnow()
) partitionbyrange (created_at);
createtableaudit_events_2026_01partition of audit_events
forvaluesfrom ('2026-01-01') to ('2026-01-01'::date+ interval '1 month');
createtableaudit_events_2026_02partition of audit_events
forvaluesfrom ('2026-02-01') to ('2026-02-01'::date+ interval '1 month');
createtableaudit_events_2026_03partition of audit_events
forvaluesfrom ('2026-03-01') to ('2026-03-01'::date+ interval '1 month');
createtableaudit_events_2026_04partition of audit_events
forvaluesfrom ('2026-04-01') to ('2026-04-01'::date+ interval '1 month');
createtableaudit_events_2026_05partition of audit_events
forvaluesfrom ('2026-05-01') to ('2026-05-01'::date+ interval '1 month');
createtableaudit_events_2026_06partition of audit_events
forvaluesfrom ('2026-06-01') to ('2026-06-01'::date+ interval '1 month');
createtableaudit_events_2026_07partition of audit_events
forvaluesfrom ('2026-07-01') to ('2026-07-01'::date+ interval '1 month');
createtableaudit_events_2026_08partition of audit_events
forvaluesfrom ('2026-08-01') to ('2026-08-01'::date+ interval '1 month');
createtableaudit_events_2026_09partition of audit_events
forvaluesfrom ('2026-09-01') to ('2026-09-01'::date+ interval '1 month');
createtableaudit_events_2026_10partition of audit_events
forvaluesfrom ('2026-10-01') to ('2026-10-01'::date+ interval '1 month');
createtableaudit_events_2026_11partition of audit_events
forvaluesfrom ('2026-11-01') to ('2026-11-01'::date+ interval '1 month');
createtableaudit_events_2026_12partition of audit_events
forvaluesfrom ('2026-12-01') to ('2026-12-01'::date+ interval '1 month');
insert into audit_events (kind, session_id, payload, created_at)
select kind, session_id, payload, created_at from audit_events_legacy;
droptable audit_events_legacy;
src/db/migrations/0010_user_roles.sql
+25-0
Difftastic 0.69.0 · SQL: changed syntax is marked
Placing the discussions of this file for the layout of this page…
Unchanged since the baseline
-- 0010: roles move off the users table into their own join table-- 0010: roles move off the users table into their own join table
createtableifnotexists roles (
nametextprimary key,
descriptiontextnot nulldefault''
);
insert into roles (name, description) values
('reviewer','read diffs and comment'),
('maintainer','publish reviews to GitHub'),
('admin','session and audit administration')
on conflict do nothing;
createtableifnotexists user_roles (
user_id uuid not nullreferences users (id) on delete cascade,
roletextnot nullreferences roles (name) on delete restrict,
granted_attimestamptznot nulldefaultnow(),
primary key (user_id, role)
);
insert into user_roles (user_id, role)
select id, 'reviewer'from users whereroleisnull;
insert into user_roles (user_id, role)
select id, rolefrom users whereroleis not null;
altertable users drop column ifexistsrole;
src/db/migrations/0011_sessions_device.sql
+14-0
Difftastic 0.69.0 · SQL: added file, no line evidence
Placing the discussions of this file for the layout of this page…
Unchanged since the baseline
-- 0011: remember which device a session came from
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.
Before, lines 1–8.
Changelog
Unreleased
nothing yet
0.4.0
After, lines 1–24.
Changelog
Unreleased
Added
Token rotation on use, with an audit event per rotation.
Per-session and per-IP rate limiting, persisted across restarts.
Login form with local validation and a one-time code field.
Server-sent event stream for live review updates.
Changed
Default listen port is 8080.
Passwords are hashed with scrypt instead of the placeholder hash.
Sessions expire after 12 hours rather than never.
Fixed
Empty credentials no longer mint a token.
JSON parsing no longer throws on an empty body.
0.4.0
These lines have no changes since snapshot #1.
Placing the discussions of this file for the layout of this page…
Unchanged since the baseline
# Changelog# Changelog
## Unreleased## Unreleased
- nothing yet### Added
- Token rotation on use, with an audit event per rotation.
- Per-session and per-IP rate limiting, persisted across restarts.
- Login form with local validation and a one-time code field.
- Server-sent event stream for live review updates.
### Changed
- Default listen port is 8080.
- Passwords are hashed with scrypt instead of the placeholder hash.
- Sessions expire after 12 hours rather than never.
### Fixed
- Empty credentials no longer mint a token.
- JSON parsing no longer throws on an empty body.
## Unreleased
- nothing yet
## Unreleased
### Added
- Token rotation on use, with an audit event per rotation.
- Per-session and per-IP rate limiting, persisted across restarts.
- Login form with local validation and a one-time code field.
- Server-sent event stream for live review updates.
### Changed
- Default listen port is 8080.
- Passwords are hashed with scrypt instead of the placeholder hash.
- Sessions expire after 12 hours rather than never.
### Fixed
- Empty credentials no longer mint a token.
- JSON parsing no longer throws on an empty body.
## 0.4.0## 0.4.0
docs/api.md
+35-10
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.
Before, lines 3–16.
Every endpoint answers JSON and requires a bearer token.
Endpoints
Method
Path
Purpose
POST
/login
exchange a user name for a token
Errors
Errors are plain strings in a message field; the status is always 200 or 500.
After, lines 3–33.
Every endpoint answers JSON and requires a bearer token.
Endpoints
| Method | Path | Purpose |
| --- | --- | --- |
| POST | /login | exchange credentials for a session |
| POST | /logout | revoke the current session |
| POST | /refresh | rotate the current token |
| GET | /sessions | list the caller’s sessions |
| DELETE | /sessions/:id | revoke one session |
| GET | /events | server-sent event stream |
Errors
Errors carry a machine-readable code and a human message.
401 UNAUTHORIZED — missing or unknown token.
403 FORBIDDEN — the session lacks the required role.
429 RATE_LIMITED — the token bucket is empty; retry after a second.
500 — anything unhandled, logged with the request url.
After, lines 32–41.
Rate limits
Requests are limited per session, falling back to the remote address for anonymous callers. The budget is a token bucket: burst tokens, refilled at perSecond.
Read endpoints cost 1 token.
Sign-in costs 5 tokens, so credential stuffing runs out quickly.
Buckets are persisted, so a restart does not hand out a fresh budget.
These lines have no changes since snapshot #1.
Placing the discussions of this file for the layout of this page…
# HTTP API# HTTP API
Unchanged since the baseline
Every endpoint answers JSON and requires a bearer token.Every endpoint answers JSON and requires a bearer token.
| POST | `/login` | exchange a user name for a token || --- | --- | --- |
## Errors| POST | `/login` | exchange credentials for a session |
Errors are plain strings in a `message` field; the status is always 200 or 500.| POST | `/logout` | revoke the current session |
| POST | `/refresh` | rotate the current token |
| GET | `/sessions` | list the caller’s sessions |
| DELETE | `/sessions/:id` | revoke one session |
| GET | `/events` | server-sent event stream |
## Errors
Errors carry a machine-readable code and a human message.
- `401 UNAUTHORIZED` — missing or unknown token.
- `403 FORBIDDEN` — the session lacks the required role.
- `429 RATE_LIMITED` — the token bucket is empty; retry after a second.
- `500` — anything unhandled, logged with the request url.
## Endpoints
| Method | Path | Purpose |
| --- | --- | --- |
| POST | `/login` | exchange a user name for a token |
## Errors
Errors are plain strings in a `message` field; the status is always 200 or 500.
## Endpoints
| Method | Path | Purpose |
| --- | --- | --- |
| POST | `/login` | exchange credentials for a session |
| POST | `/logout` | revoke the current session |
| POST | `/refresh` | rotate the current token |
| GET | `/sessions` | list the caller’s sessions |
| DELETE | `/sessions/:id` | revoke one session |
| GET | `/events` | server-sent event stream |
## Errors
Errors carry a machine-readable code and a human message.
- `401 UNAUTHORIZED` — missing or unknown token.
- `403 FORBIDDEN` — the session lacks the required role.
- `429 RATE_LIMITED` — the token bucket is empty; retry after a second.
- `500` — anything unhandled, logged with the request url.
<!-- older sections --><!-- older sections -->
Unchanged since the baseline
<!-- older sections --><!-- older sections -->
## Rate limits
Requests are limited per session, falling back to the remote address for anonymous callers. The budget is a token bucket: `burst` tokens, refilled at `perSecond`.
- Read endpoints cost 1 token.
- Sign-in costs 5 tokens, so credential stuffing runs out quickly.
- Buckets are persisted, so a restart does not hand out a fresh budget.
docs/architecture.md
+34-11
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.
Before, lines 3–16.
How a request travels through the service.
Before: the complete diagram, lines 5–9. Changed lines 5–9. The diagram marks no changed element, because a fence line changed; the source diff shows the exact lines.
flowchart LR
Browser[browser] --> Routes[routes]
Routes --> DB[(postgres)]
Layers
The router is the only layer: it reads the body, runs a query and writes JSON.
After, lines 3–38.
How a request travels through the service.
After: the complete diagram, lines 5–14. Changed lines 5–14. The diagram marks no changed element, because a fence line changed; the source diff shows the exact lines.
Middleware is a plain array: each layer either answers or calls next(). There is no framework, so the whole chain fits on one screen in src/server/http.ts.
cors — echoes allowed origins, answers preflights.
rateLimit — token bucket per session or address.
withSession — resolves the bearer token to a session row.
routes — matches method + path, runs the guard, then the handler.
Data
Sessions and audit events are the only tables this PR touches. Audit events are partitioned by month so retention is a detach rather than a delete.
Failure modes
Every handler funnels errors through statusFor, so an unmapped error is a 500 with the url logged — never a leaked stack.
Postgres unavailable — the pool retries with jittered backoff, /ready fails, the load balancer drains the pod.
Rate-limit table unavailable — buckets fall back to memory; budgets reset on restart.
SSE proxy buffering — the heartbeat keeps the connection alive but frames arrive late.
After, lines 46–50.
Before: the complete diagram, lines 19–37. Changed line 34. A red band with the label “Removed:” marks each changed step, block, group and activation, a changed participant has a red box and the label in its name, and a changed box has a red border and a title that starts with the label on a plain backing.
sequenceDiagram
participant Client
participant Auth
participant Store
Client->>Auth: POST /login
Auth->>Store: find user
Store-->>Auth: session id
Auth-->>Client: token
loop every request
Client->>Auth: bearer token
Auth->>Store: find session
Store-->>Auth: session
end
Client->>Auth: GET /me
Auth->>Store: read session
Store-->>Auth: member
Auth-->>Client: profile
After: the complete diagram, lines 41–60. Changed lines 48, 57. A green band with the label “Added:” marks each changed step, block, group and activation, a changed participant has a green box and the label in its name, and a changed box has a green border and a title that starts with the label on a plain backing.
sequenceDiagram
participant Client
participant Auth
participant Store
Client->>Auth: POST /login
Auth->>Store: find user
Auth->>Store: write session with status member
Store-->>Auth: session id
Auth-->>Client: token
loop every request
Client->>Auth: bearer token
Auth->>Store: find session
Store-->>Auth: session
end
Client->>Auth: GET /me
Auth->>Store: read session including the member status
Store-->>Auth: member
Auth-->>Client: profile
Before, lines 32–36.
These lines belong to a diagram that shows complete with an earlier change of this article. Show the complete diagram.
end
Client->>Auth: GET /me
Auth->>Store: read session
Store-->>Auth: member
Auth-->>Client: profile
After, lines 55–59.
These lines belong to a diagram that shows complete with an earlier change of this article. Show the complete diagram.
end
Client->>Auth: GET /me
Auth->>Store: read session including the member status
Store-->>Auth: member
Auth-->>Client: profile
These lines have no changes since snapshot #1.
Placing the discussions of this file for the layout of this page…
# Architecture# Architecture
Unchanged since the baseline
How a request travels through the service.How a request travels through the service.
The router is the only layer: it reads the body, runs a query and writes JSON. Handlers --> SSE[sse broadcast]
```
## Layers
Middleware is a plain array: each layer either answers or calls `next()`. There is no framework, so the whole chain fits on one screen in `src/server/http.ts`.
- `rateLimit` — token bucket per session or address.
- `withSession` — resolves the bearer token to a session row.
- `routes` — matches method + path, runs the guard, then the handler.
## Data
Sessions and audit events are the only tables this PR touches. Audit events are partitioned by month so retention is a detach rather than a delete.
## Failure modes
Every handler funnels errors through `statusFor`, so an unmapped error is a 500 with the url logged — never a leaked stack.
- Postgres unavailable — the pool retries with jittered backoff, `/ready` fails, the load balancer drains the pod.
- Rate-limit table unavailable — buckets fall back to memory; budgets reset on restart.
- SSE proxy buffering — the heartbeat keeps the connection alive but frames arrive late.
```mermaid
flowchart LR
Browser[browser] --> Routes[routes]
Routes --> DB[(postgres)]
```
## Layers
The router is the only layer: it reads the body, runs a query and writes JSON.
```mermaid
flowchart LR
Browser[browser] --> CORS[cors]
CORS --> RL[rateLimit]
RL --> Auth[withSession]
Auth --> Routes[routes]
Routes --> Handlers[handlers]
Handlers --> DB[(postgres)]
Handlers --> SSE[sse broadcast]
```
## Layers
Middleware is a plain array: each layer either answers or calls `next()`. There is no framework, so the whole chain fits on one screen in `src/server/http.ts`.
- `rateLimit` — token bucket per session or address.
- `withSession` — resolves the bearer token to a session row.
- `routes` — matches method + path, runs the guard, then the handler.
## Data
Sessions and audit events are the only tables this PR touches. Audit events are partitioned by month so retention is a detach rather than a delete.
## Failure modes
Every handler funnels errors through `statusFor`, so an unmapped error is a 500 with the url logged — never a leaked stack.
- Postgres unavailable — the pool retries with jittered backoff, `/ready` fails, the load balancer drains the pod.
- Rate-limit table unavailable — buckets fall back to memory; budgets reset on restart.
- SSE proxy buffering — the heartbeat keeps the connection alive but frames arrive late.
<!-- diagrams for the 0.4 topology live in git history --><!-- diagrams for the 0.4 topology live in git history -->
## Session handshake## Session handshake
```mermaid```mermaid
sequenceDiagramsequenceDiagram
participant Client participant Client
participant Auth participant Auth
participant Store participant Store
Unchanged since the baseline
Client->>Auth: POST /login Client->>Auth: POST /login
Auth->>Store: find user Auth->>Store: find user
Auth->>Store: write session with status member
Store-->>Auth: session id Store-->>Auth: session id
Auth-->>Client: token Auth-->>Client: token
Unchanged since the baseline
end end
Client->>Auth: GET /me Client->>Auth: GET /me
Auth->>Store: read session Auth->>Store: read session including the member status
Auth->>Store: read session
Auth->>Store: read session including the member status
Store-->>Auth: member Store-->>Auth: member
Auth-->>Client: profile Auth-->>Client: profile
docs/auth.md
+27-8
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.
Before, lines 3–14.
How the service signs users in.
Sign-in flow
A reviewer posts a user name to /login. Any password is accepted.
Passwords are hashed with md5 and no salt.
Tokens are the user name plus a timestamp.
Sessions never expire.
After, lines 3–25.
How the service signs users in.
Sign-in flow
A reviewer posts email, password and an optional one-time code to /login. Credentials are checked before any token is minted.
On success the service creates a session row, mints a token and returns both to the browser.
The request and response shapes are in the HTTP API. Token rotation explains how a session stays fresh. Image unavailable: Session sequence
Passwords are hashed with scrypt and a per-user salt.
Tokens are 32 random bytes, base64url encoded.
Sessions expire 12 hours after creation and rotate on use.
Every sign-in writes an audit event.
Token rotation
A token older than a minute is rotated on its next use. The old token stays valid until the response is written, so a concurrent request never sees a gap.
After, lines 24–33.
Roles
Roles are attached to the session, not the token, so revoking a role takes effect on the next request.
reviewer — read the diff, leave comments.
maintainer — everything a reviewer can do, plus publishing to GitHub.
admin — session administration and audit access.
These lines have no changes since snapshot #1.
Placing the discussions of this file for the layout of this page…
# Authentication# Authentication
Unchanged since the baseline
How the service signs users in.How the service signs users in.
## Sign-in flow## Sign-in flow
A reviewer posts a user name to `/login`. Any password is accepted.A reviewer posts email, password and an optional one-time code to `/login`. Credentials are checked before any token is minted.
- Passwords are hashed with md5 and no salt.On success the service creates a session row, mints a token and returns both to the browser.
- Tokens are the user name plus a timestamp.
- Sessions never expire.
The request and response shapes are in [the HTTP API](api.md#endpoints). [Token rotation](#token-rotation) explains how a session stays fresh. 
- Passwords are hashed with scrypt and a per-user salt.
- Tokens are 32 random bytes, base64url encoded.
- Sessions expire 12 hours after creation and rotate on use.
- Every sign-in writes an audit event.
## Token rotation
A token older than a minute is rotated on its next use. The old token stays valid until the response is written, so a concurrent request never sees a gap.
## Sign-in flow
A reviewer posts a user name to `/login`. Any password is accepted.
- Passwords are hashed with md5 and no salt.
- Tokens are the user name plus a timestamp.
- Sessions never expire.
## Sign-in flow
A reviewer posts email, password and an optional one-time code to `/login`. Credentials are checked before any token is minted.
On success the service creates a session row, mints a token and returns both to the browser.

The request and response shapes are in [the HTTP API](api.md#endpoints). [Token rotation](#token-rotation) explains how a session stays fresh. 
- Passwords are hashed with scrypt and a per-user salt.
- Tokens are 32 random bytes, base64url encoded.
- Sessions expire 12 hours after creation and rotate on use.
- Every sign-in writes an audit event.
## Token rotation
A token older than a minute is rotated on its next use. The old token stays valid until the response is written, so a concurrent request never sees a gap.
Roles are attached to the session, not the token, so revoking a role takes effect on the next request.
- `reviewer` — read the diff, leave comments.
- `maintainer` — everything a reviewer can do, plus publishing to GitHub.
- `admin` — session administration and audit access.
docs/faq.md
+0-16
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.
Before, lines 1–20. The change removes these lines.
FAQ
Why can I not sign out?
There is no /logout; drop the token and stop sending it.
Why did my token stop working after a deploy?
Tokens were held in memory, so a restart invalidated all of them.
Why do two people share a rate-limit budget?
Budgets were per IP, so everyone behind one NAT shared 60 requests a minute.
Why is my password in the logs?
The debug routes printed the request body. Do not enable them in production.
How long does a session last?
These lines have no changes since snapshot #1.
Placing the discussions of this file for the layout of this page…
Unchanged since the baseline
# FAQ# FAQ
## Why can I not sign out?
There is no `/logout`; drop the token and stop sending it.
## Why did my token stop working after a deploy?
Tokens were held in memory, so a restart invalidated all of them.
## Why do two people share a rate-limit budget?
Budgets were per IP, so everyone behind one NAT shared 60 requests a minute.
## Why is my password in the logs?
The debug routes printed the request body. Do not enable them in production.
## How long does a session last?## How long does a session last?
docs/operations.md
+20-3
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.
Before, lines 5–8.
Deploy
Copy the directory onto the box and restart the process. There are no migrations.
After, lines 5–12.
Deploy
CI builds the image on every merge to main. Deploys are a tag push; the runtime reads PORT and the database URL from the environment.
Migrations run before the new image takes traffic (pnpm migrate).
0009_audit_partitions.sql rewrites the audit table — run it in a maintenance window.
Rate-limit buckets survive restarts, so a rollback does not widen the budget.
Before, lines 9–12.
Health checks
There is no health endpoint; check the port with nc.
After, lines 13–24.
Health checks
/health answers as soon as the process is up. /ready additionally checks the pool can serve a query, so it is the one to wire into the load balancer.
Runbooks
A reviewer is locked out. Check /audit?kind=login_failed for their session, then clear their bucket with resetBuckets() via the admin console.
Sessions pile up.expireStaleSessions runs hourly; if it is behind, the sessions_touched_idx index is the first thing to check.
SSE clients drop. The stream sends a comment frame every 15s; a proxy buffering responses will still cut it — confirm X-Accel-Buffering: no survives.
Before, lines 13–17.
Dashboards
A single request counter, read from the log.
After, lines 25–34.
Dashboards
Every handler reports its duration through metrics.observe, keyed by route.
p95 login latency — should sit under 300ms with scrypt.
Rate-limited responses per minute — a spike means credential stuffing.
Open SSE connections — should track the number of reviewers.
Audit write failures — must be zero; they are the compliance trail.
These lines have no changes since snapshot #1.
Placing the discussions of this file for the layout of this page…
# Operations# Operations
Running the service on call.Running the service on call.
Unchanged since the baseline
## Deploy## Deploy
Copy the directory onto the box and restart the process. There are no migrations.CI builds the image on every merge to `main`. Deploys are a tag push; the runtime reads `PORT` and the database URL from the environment.
- Migrations run before the new image takes traffic (`pnpm migrate`).
- `0009_audit_partitions.sql` rewrites the audit table — run it in a maintenance window.
- Rate-limit buckets survive restarts, so a rollback does not widen the budget.
Copy the directory onto the box and restart the process. There are no migrations.
CI builds the image on every merge to `main`. Deploys are a tag push; the runtime reads `PORT` and the database URL from the environment.
- Migrations run before the new image takes traffic (`pnpm migrate`).
- `0009_audit_partitions.sql` rewrites the audit table — run it in a maintenance window.
- Rate-limit buckets survive restarts, so a rollback does not widen the budget.
## Health checks## Health checks
There is no health endpoint; check the port with `nc`.`/health` answers as soon as the process is up. `/ready` additionally checks the pool can serve a query, so it is the one to wire into the load balancer.
## Runbooks
**A reviewer is locked out.** Check `/audit?kind=login_failed` for their session, then clear their bucket with `resetBuckets()` via the admin console.
**Sessions pile up.**`expireStaleSessions` runs hourly; if it is behind, the `sessions_touched_idx` index is the first thing to check.
**SSE clients drop.** The stream sends a comment frame every 15s; a proxy buffering responses will still cut it — confirm `X-Accel-Buffering: no` survives.
There is no health endpoint; check the port with `nc`.
`/health` answers as soon as the process is up. `/ready` additionally checks the pool can serve a query, so it is the one to wire into the load balancer.
## Runbooks
**A reviewer is locked out.** Check `/audit?kind=login_failed` for their session, then clear their bucket with `resetBuckets()` via the admin console.
**Sessions pile up.**`expireStaleSessions` runs hourly; if it is behind, the `sessions_touched_idx` index is the first thing to check.
**SSE clients drop.** The stream sends a comment frame every 15s; a proxy buffering responses will still cut it — confirm `X-Accel-Buffering: no` survives.
## Dashboards## Dashboards
A single request counter, read from the log.Every handler reports its duration through `metrics.observe`, keyed by route.
- p95 login latency — should sit under 300ms with scrypt.
- Rate-limited responses per minute — a spike means credential stuffing.
- Open SSE connections — should track the number of reviewers.
- Audit write failures — must be zero; they are the compliance trail.
A single request counter, read from the log.
Every handler reports its duration through `metrics.observe`, keyed by route.
- p95 login latency — should sit under 300ms with scrypt.
- Rate-limited responses per minute — a spike means credential stuffing.
- Open SSE connections — should track the number of reviewers.
- Audit write failures — must be zero; they are the compliance trail.
<!-- pre-0.5 notes --><!-- pre-0.5 notes -->
docs/security.md
+20-0
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.
After, lines 1–20.
Security
What this service promises and what it does not.
Credentials
Passwords are hashed with scrypt and a per-user 16-byte salt. Verification is constant-time. Nothing logs a password, a token or a hash.
Tokens
Tokens are 32 random bytes, base64url encoded, stored as-is and compared in constant time. A token is only ever accepted over TLS.
Rotation on use limits the window a leaked token is useful.
Revocation is immediate: the session row is checked on every request.
Audit rows record every sign-in, rotation and revocation.
Reporting
Mail security@example.com. We answer within two working days and credit reporters in the changelog unless asked otherwise.
These lines have no changes since snapshot #1.
Placing the discussions of this file for the layout of this page…
Unchanged since the baseline
# Security
What this service promises and what it does not.
## Credentials
Passwords are hashed with scrypt and a per-user 16-byte salt. Verification is constant-time. Nothing logs a password, a token or a hash.
## Tokens
Tokens are 32 random bytes, base64url encoded, stored as-is and compared in constant time. A token is only ever accepted over TLS.
- Rotation on use limits the window a leaked token is useful.
- Revocation is immediate: the session row is checked on every request.
- Audit rows record every sign-in, rotation and revocation.
## Reporting
Mail security@example.com. We answer within two working days and credit reporters in the changelog unless asked otherwise.
docs/sessions-old.md
+0-129
Line diff: Difftastic has no parser for this file and compared it as text. Word comparison marks the changed words of replaced lines.
Before, lines 1–129. The change deletes this file.
Sessions (0.4)
Sessions never expired and the token was derived from the user name.
Creating a session
POST /login with a user name. Any password was accepted.
Ending a session
There was no /logout; clients dropped the token and moved on.
Known problems
Tokens were guessable from the user name and a timestamp.
Nothing expired, so a leaked token was valid forever.
No audit trail, so a compromise could not be reconstructed.
Rate limiting used fixed windows, allowing 2x bursts across a boundary.
These lines have no changes since snapshot #1.
Placing the discussions of this file for the layout of this page…
Unchanged since the baseline
# Sessions (0.4)
Sessions never expired and the token was derived from the user name.
## Creating a session
POST /login with a user name. Any password was accepted.
## Ending a session
There was no /logout; clients dropped the token and moved on.
## Known problems
- Tokens were guessable from the user name and a timestamp.
- Nothing expired, so a leaked token was valid forever.
- No audit trail, so a compromise could not be reconstructed.
- Rate limiting used fixed windows, allowing 2x bursts across a boundary.
Difftastic 0.69.0 · YAML: changed syntax is marked
Placing the discussions of this file for the layout of this page…
apiVersion: apps/v1apiVersion: apps/v1
kind: Deploymentkind: Deployment
metadata:metadata:
Unchanged since the baseline
name:accounts-apiname:accounts-api
spec:spec:
replicas:1replicas:3
template:strategy:
spec:type:RollingUpdate
containers:rollingUpdate:
-name: appmaxSurge:1
maxUnavailable:0
selector:
matchLabels:
app:accounts-api
template:
metadata:
labels:
app:accounts-api
spec:
containers:
-name: app
image:ghcr.io/acme/accounts-api:latest
ports:
-containerPort: 8080
env:
-name: PORT
value:"8080"
-name: LOG_LEVEL
value:info
-name: DATABASE_URL
valueFrom:
secretKeyRef:
name:accounts-api
key:database-url
readinessProbe:
httpGet:
path:/ready
port:8080
periodSeconds:5
livenessProbe:
httpGet:
path:/health
port:8080
periodSeconds:10
resources:
requests:
cpu:100m
memory:192Mi
limits:
cpu:"1"
memory:512Mi
replicas:1
template:
spec:
containers:
-name: app
replicas:3
strategy:
type:RollingUpdate
rollingUpdate:
maxSurge:1
maxUnavailable:0
selector:
matchLabels:
app:accounts-api
template:
metadata:
labels:
app:accounts-api
spec:
containers:
-name: app
image:ghcr.io/acme/accounts-api:latest
ports:
-containerPort: 8080
env:
-name: PORT
value:"8080"
-name: LOG_LEVEL
value:info
-name: DATABASE_URL
valueFrom:
secretKeyRef:
name:accounts-api
key:database-url
readinessProbe:
httpGet:
path:/ready
port:8080
periodSeconds:5
livenessProbe:
httpGet:
path:/health
port:8080
periodSeconds:10
resources:
requests:
cpu:100m
memory:192Mi
limits:
cpu:"1"
memory:512Mi
Job logging rename
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.
Mechanical change · 6 files · 6 hunks
Replace import { logger } from '../lib/logger'; with import { log } from '../lib/log';, and each logger.info( call with log.info(. Nothing else changes.
Verification:
Applied both replacements to the captured old side of each job file and compared the result with its captured new side: all six files match exactly. No job ran.
2 files below show the representative examples, and 4 matching files wait in the remaining group. A reviewed example marks only its own file.
src/jobs/cleanup.ts
+3-3
Difftastic 0.69.0 · TypeScript: changed syntax is marked
Placing the discussions of this file for the layout of this page…
Unchanged since the baseline
// The cleanup job, which the scheduler runs every night.// The cleanup job, which the scheduler runs every night.
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.
tests/auth.test.ts
+34-12
Difftastic 0.69.0 · TypeScript: changed syntax is marked
Placing the discussions of this file for the layout of this page…