Skip to content

security: add server/auth session layer and redacting logger (PR 1.1) - #9

Merged
Jeston10 merged 4 commits into
milestone/p1-securityfrom
security/session-and-logger
Sep 16, 2026
Merged

Jeston10 merged 4 commits into
milestone/p1-securityfrom
security/session-and-logger

Conversation

@Jeston10

Copy link
Copy Markdown
Owner

Summary

PR 1.1 of docs/MILESTONES.md (Phase 1 — security hardening). Implements SECURITY §2.1 (sessions) and §2.11 (logging) as the first real server/ modules of the target architecture.

  • server/auth/session-core.ts — pure session logic behind SessionAuth / SessionCookieStore interfaces; hardened cookie (httpOnly, secure in prod, sameSite=lax, path=/, 7-day TTL, __Host- prefix in production)
  • server/auth/session.ts — Next adapter: getCurrentUser (React.cache — one verification per request), requireUser → AppError('UNAUTHENTICATED'), *Checked variants for sensitive ops (R22), destroySession clears cookie and revokes refresh tokens
  • server/errors.ts (AppError, fixed code set) and server/observability/logger.ts (pino, key-path redaction for cookies/tokens/emails/transcripts)
  • Layouts, pages, signout and profile routes migrated; dead x-next-url/PUBLIC_ROUTES code removed; lib/actions/auth.action.ts reduced to sign-in/up + streak helpers (gone in P1.4)

Type

  • security

Verification

  • pnpm lint ✔ · pnpm typecheck ✔ · knip ✔ · vitest 17/17 (session core with fakes; logger redaction asserts no cookie/token/email/transcript text is emitted) · next build ✔
  • Runtime smoke on next start with a throwaway Auth user: anonymous /profile → 307; __Host-session cookie → 200; POST /api/auth/signout clears the cookie and the old cookie fails the revocation check afterwards; server log contains no cookie material. Test user and doc deleted.
  • Grep gates from the P1.1 row: console.* in app code = 0; process.env outside config/env.ts = 0

Server checklist

  • Auth is the first statement in the migrated routes (requireUserChecked in profile update)
  • No process.env outside config/env.ts; no PII in logs (redaction tested)
  • Tests for the unauthenticated path (readSession null cases)
  • zod validation / rate limits / ownership — P1.4 / P1.5 (this PR does not add endpoints)

Risk watch-list

  • Rows checked: R1, R22
  • R1: log already removed (PR 0.1); this PR adds revokeRefreshTokens on sign-out. After this deploys, run the one-off all-users revocation (script in P1.1 follow-up note below). R22 accepted as documented.

Follow-up before closing R1: one-off scripts/revoke-all-sessions.ts (admin listUsers → revokeRefreshTokens) run once against production after deploy; tracked in docs/RISKS.md.

🤖 Generated with Claude Code

Jeston10 and others added 2 commits September 16, 2026 01:04
PR 1.1 of docs/MILESTONES.md (SECURITY §2.1, §2.11).

- server/auth/session-core.ts: pure session logic behind small
  SessionAuth / SessionCookieStore interfaces (unit-tested with fakes).
  Hardened cookie: httpOnly, secure in production, sameSite=lax,
  path=/, 7-day TTL, `__Host-` prefix in production.
- server/auth/session.ts: Next adapter. getCurrentUser is React.cache'd
  (one verification per request); requireUser throws
  AppError('UNAUTHENTICATED'); *Checked variants verify revocation for
  sensitive operations (RISKS R22); destroySession clears the cookie
  and revokes refresh tokens.
- server/errors.ts: AppError with a fixed code set (Result helpers in
  P2.1). server/observability/logger.ts: pino with key-path redaction
  for cookies, tokens, emails, transcripts; pino externalised from the
  server bundle.
- (root) and (auth) layouts, pages, signout and profile routes now use
  the session layer; the dead x-next-url / PUBLIC_ROUTES code is gone;
  lib/actions/auth.action.ts keeps only sign-in/up and streak helpers
  until P1.4.

Verified: pnpm lint, typecheck, knip, vitest 17/17 (session core +
redaction), next build; runtime smoke on `next start` with a throwaway
user: anonymous 307, `__Host-session` 200, signout clears cookie and
the old cookie fails the revocation check; no cookie text in logs.
Grep gates: console.* = 0, process.env outside config/env.ts = 0.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Sep 15, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
just-prep-ai-interview-z3cv Error Error Sep 15, 2026 7:55pm UTC

Copilot AI lite review requested due to automatic review settings September 15, 2026 19:39

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Jeston10
Jeston10 merged commit 78df1b2 into milestone/p1-security Sep 16, 2026
6 of 7 checks passed
@Jeston10
Jeston10 deleted the security/session-and-logger branch September 16, 2026 03:48

This branch had an error being deployed

1 failed deployment
Preview — 127016d3 Deployed Sep 15, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants